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
Eval and block problems
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="Ryan Leavengood, post: 4485806"] ng: [code snipped] Good question! Because by researching the answer I learned you can just pass a block to define_method: class A def initialize(x) @x =3D x end def self.def_me(cmd, &block) define_method(cmd, &block) end def_me("foo") do puts "x is #@x" end end A.new(1).foo A.new(2).foo __END__ But strictly speaking in this case the separate def_me method is redundant since you could just call define_method directly. Ryan [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
Eval and block problems
Top