Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
Adding instance methods to class at runtime
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Jon A. Lambert, post: 4481584"] Excellent Thank you. I think my problem was scope then. Here's what I be doing and it now works like a charm. $ cat cmd1/cmd_bar.rb module Command def cmd_bar puts "cmd_bar one called" end end $ cat cmd2/cmd_bar.rb module Command def cmd_bar puts "cmd_bar two called" end end $ cat testcmds.rb class Foo end def load1 cmds = Dir.glob("cmd1/cmd_*.rb") cmds.each {|c| load(c)} Foo.send(:include,Command) end def load2 cmds = Dir.glob("cmd2/cmd_*.rb") cmds.each {|c| load(c)} Foo.send(:include,Command) end f = Foo.new load1 f.cmd_bar load2 f.cmd_bar $ ruby testcmds.rb cmd_bar one called cmd_bar two called [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
Adding instance methods to class at runtime
Top