Created
April 13, 2013 21:42
-
-
Save kdavh/5380188 to your computer and use it in GitHub Desktop.
Question about scope when using `exend ModuleName` and `::define_method` in a class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module M | |
def i_method | |
define_method(:new_method) do | |
"I am from i_method, but I should be an instance method" | |
end | |
end | |
end | |
class C | |
extend M | |
end | |
C.i_method | |
C.new.new_method | |
# The arguments that would also work on line 3: | |
# self.send(:define_method, :new_method) do | |
# send(:define_method, :new_method) do | |
# What is going on? | |
# I thought `self.define_method` and `define_method` would be the same? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment