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
Scope in Method Definitions
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="Curt Sampson, post: 4466402"] Presumably there's some theory behind this, but this is a seeming inconsistency in the language that I don't understand. foo = "foo" C = Class.new() { def method1; puts foo; end define_method(:method2) { puts foo } } C.new.method2 # prints "foo" C.new.method1 # NameError: undefined local variable or method `foo' Can someone explain why this is sensible behaviour? cjs [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
Scope in Method Definitions
Top