From: Robert Klemme Date: 2004-10-27T17:49:03+09:00 Subject: Re: OpenStruct and #send "Hal Fulton" schrieb im Newsbeitrag news:417F596C.5080208@hypermetrics.com... > Hmm... should this work or not? > > In other words: Bug, anomaly, feature, or just user error? :) > > Below, I expected/wanted x.send("foo") to give me 6. > > Hal > > > [hal@dhcppc2 kronos]$ irb > irb(main):001:0> require 'ostruct' > => true > irb(main):002:0> def foo > irb(main):003:1> puts "I'm a method" > irb(main):004:1> end > => nil > irb(main):005:0> x = OpenStruct.new > => > irb(main):006:0> x.bar = 5 > => 5 > irb(main):007:0> x.foo = 6 > => 6 > irb(main):008:0> x.send("bar") > => 5 > irb(main):009:0> x.send("foo") > I'm a method > => nil > irb(main):010:0> This looks like an IRB anomaly: 10:43:19 [robert.klemme]: irbs >> require 'ostruct' => true >> x = OpenStruct.new => >> p x.public_methods.select {|o| /^foo/ =~ o} [] => nil >> def foo() "buh!" end => nil >> p x.public_methods.select {|o| /^foo/ =~ o} ["foo"] => nil >> exit 10:43:29 [robert.klemme]: ruby /c/temp/ruby/ostruct-foo.rb [] [] 10:43:35 [robert.klemme]: cat /c/temp/ruby/ostruct-foo.rb require 'ostruct' x = OpenStruct.new p x.public_methods.select {|o| /^foo/ =~ o} def foo() "buh!" end p x.public_methods.select {|o| /^foo/ =~ o} 10:43:39 [robert.klemme]: Kind regards robert