Sunday, October 14, 2012

Re: [Rails] Re: Why does Kernel define class_eval?

This is not a standard ruby method.
The Kernel module is being monkeypatched by the activesupport gem.

[13] pry(main)> o=Object.new
=> #<Object:0x000000047102d8>
[14] pry(main)> show-method o.class_eval

From: /home/user/.rvm/gems/ruby-1.9.3-p194@rocas/gems/activesupport-3.2.8/lib/active_support/core_ext/kernel/singleton_class.rb @ line 10:
Number of lines: 3
Owner: Kernel
Visibility: public

def class_eval(*args, &block)
  singleton_class.class_eval(*args, &block)
end
[15] pry(main)> o.class_eval { def test; :test; end;}
=> nil
[16] pry(main)> o.test
=> :test


2012/10/14 7stud -- <lists@ruby-forum.com>
obj = Object.new
obj.class_eval {}

--output:--
1.rb:2:in `<main>': undefined method `class_eval' for
#<Object:0x000001010913f0> (NoMethodError)


puts Kernel.instance_methods(false).include? :class_eval

--output:--
false


$ ruby --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin10.8.0]

$ rvm use 1.8.7

$ ruby --version
ruby 1.8.7 (2012-06-29 patchlevel 370) [i686-darwin10.8.0]

obj = Object.new
obj.class_eval {}

--output:--
1.rb:2:in `<main>': undefined method `class_eval' for
#<Object:0x000001010913f0> (NoMethodError)


puts Kernel.instance_methods(false).include? :class_eval

--output:--
false

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.





--
Piantanida, Ignacio Julián

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate