T
Tuan Bui
Hiya,
If I want to create a hash table with the values containing methods to
call, how do i call these methods if they need parameters? Here's an
example:
irb(main):001:0> def methodone
irb(main):002:1> puts "hi, i am method one"
irb(main):003:1> end
=> nil
irb(main):004:0> def methodtwo(input)
irb(main):005:1> puts input
irb(main):006:1> end
=> nil
irb(main):007:0> myhash = { 'foo' => 'methodone', 'bar' => 'methodtwo' }
=> {"foo"=>"methodone", "bar"=>"methodtwo"}
irb(main):008:0> eval myhash["foo"]
hi, i am method one
=> nil
irb(main):009:0> eval myhash["bar"] "hi, i am method two"
SyntaxError: compile error
(irb):9: parse error
from (irb):9
irb(main):010:0>
In other words, how do I pass a parameter to method two?
If my implementation of what I want to do looks lame, please let me know
of a better way... I am pretty new to Ruby.
Thanks!
Tuan
If I want to create a hash table with the values containing methods to
call, how do i call these methods if they need parameters? Here's an
example:
irb(main):001:0> def methodone
irb(main):002:1> puts "hi, i am method one"
irb(main):003:1> end
=> nil
irb(main):004:0> def methodtwo(input)
irb(main):005:1> puts input
irb(main):006:1> end
=> nil
irb(main):007:0> myhash = { 'foo' => 'methodone', 'bar' => 'methodtwo' }
=> {"foo"=>"methodone", "bar"=>"methodtwo"}
irb(main):008:0> eval myhash["foo"]
hi, i am method one
=> nil
irb(main):009:0> eval myhash["bar"] "hi, i am method two"
SyntaxError: compile error
(irb):9: parse error
from (irb):9
irb(main):010:0>
In other words, how do I pass a parameter to method two?
If my implementation of what I want to do looks lame, please let me know
of a better way... I am pretty new to Ruby.
Thanks!
Tuan