define_method issue

R

Raj Singh

Based on the following example should I conclude whether I use
instance_eval or class_eval, define_method always creates an instance
method.

class Music
end

Music.instance_eval do
define_method :jazz do
puts 'i am jazz'
end
end

Music.class_eval do
define_method :rock do
puts 'i am rock'
end
end

Music.jazz rescue puts 'Music.jazz failed'
Music.rock rescue puts 'Music.rock failed'
Music.new.jazz rescue puts 'Music.new.jazz failed'
Music.new.rock rescue puts 'Music.new.rock failed'

output is:
Music.jazz failed
Music.rock failed
i am jazz
i am rock
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top