Skip to content

Instantly share code, notes, and snippets.

@kdavh
Created April 13, 2013 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdavh/5380188 to your computer and use it in GitHub Desktop.
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
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