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
can I tighten this up with block or eval?
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="matt neuburg, post: 4634068"] Actually, I have to keep the architecture I've got - greeter is going to be called without a parameter, that's just how it is. (The problem as I posed it is just a schematic reduction of a vast existing architecture that does something else entirely.) However, your solution shows me exactly the trick I was missing: I need to turn @howdy into a local so that a block can see it: class ClassMaker def initialize(s); @howdy = s; end def greeter greeting = @howdy # the magic step! Class.new do define_method :hello do puts greeting end end.new end end ClassMaker.new("gday").greeter.hello Thanks! It's nice to stop banging myself over the head with a hammer... :) m. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
can I tighten this up with block or eval?
Top