About method definition

################

case.1

################
class X
def x
def xx; end
end
end

x = X.new
x.x

p x.singleton_methods.grep(/xx/) #=> []

################

case.2

################
class X
def x
instance_eval “def xx; end”
end
end

x = X.new
x.x

p x.singleton_methods.grep(/xx/) #=> [:xx]

###############################################################

Is not instance level when x method is called in case1 ??

What’s the difference between the two cases ???

###############################################################

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs