I
Iain Barnett
Hello,
Just playing around with a few things in Ruby, and I'm wondering why the =
following script would throw an error? I'm using Ruby 1.9.1 on OSX 10.6
#!/usr/bin/env ruby -wKU
puts "Welcome"
h =3D { 'a' =3D> lambda { puts "again again!" } ,
'b' =3D> lambda { puts "oh no!" }
}
while true
x =3D STDIN.getc
break if x =3D=3D 'q'
h[x].call
end
$ ./getchar.rb
Welcome
a
again again!
/getchar.rb:12:in `<main>': undefined method `call' for nil:NilClass =
(NoMethodError)
$ ./getchar.rb
Welcome
b
on no!
/getchar.rb:12:in `<main>': undefined method `call' for nil:NilClass =
(NoMethodError)
Any help is much appreciated
Regards,
Iain
Just playing around with a few things in Ruby, and I'm wondering why the =
following script would throw an error? I'm using Ruby 1.9.1 on OSX 10.6
#!/usr/bin/env ruby -wKU
puts "Welcome"
h =3D { 'a' =3D> lambda { puts "again again!" } ,
'b' =3D> lambda { puts "oh no!" }
}
while true
x =3D STDIN.getc
break if x =3D=3D 'q'
h[x].call
end
$ ./getchar.rb
Welcome
a
again again!
/getchar.rb:12:in `<main>': undefined method `call' for nil:NilClass =
(NoMethodError)
$ ./getchar.rb
Welcome
b
on no!
/getchar.rb:12:in `<main>': undefined method `call' for nil:NilClass =
(NoMethodError)
Any help is much appreciated
Regards,
Iain