Kernel on Ruby 1.9.2

Now it seems like Kernel it is not working the same way
I had this code in 1.8.7

module Kernel
private
   def method_name
      caller[0] =~ /`([^']*)'/ and $1
   end
end

and now it is giving me this error when calling method_name
NoMethodError: private method `method_name' called for
#<MyTest:0x269e260>

···

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

Ruby - APIdock is good for tracking down this stuff. You can
search for a method, then select a Ruby version number to see where it
exists and where it doesn't. Deprecated 1.8.7 methods' descriptions
also usually refer you to a 1.9.x equivalent, if one exists.

···

On Thu, Oct 27, 2011 at 12:19 PM, Mario Ruiz <tcblues@gmail.com> wrote:

Now it seems like Kernel it is not working the same way
I had this code in 1.8.7

module Kernel
private
def method_name
caller[0] =~ /`([^']*)'/ and $1
end
end

and now it is giving me this error when calling method_name
NoMethodError: private method `method_name' called for
#<MyTest:0x269e260>

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

--
Carina

Can you show the calling code?

Kind regards

robert

···

On Thu, Oct 27, 2011 at 9:19 PM, Mario Ruiz <tcblues@gmail.com> wrote:

Now it seems like Kernel it is not working the same way
I had this code in 1.8.7

module Kernel
private
def method_name
caller[0] =~ /`([^']*)'/ and $1
end
end

and now it is giving me this error when calling method_name
NoMethodError: private method `method_name' called for
#<MyTest:0x269e260>

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

I solved this by using it as public
Also another way is to use the variable @__name__

Thanks for the help

Robert Klemme wrote in post #1028993:

···

On Thu, Oct 27, 2011 at 9:19 PM, Mario Ruiz <tcblues@gmail.com> wrote:

and now it is giving me this error when calling method_name
NoMethodError: private method `method_name' called for
#<MyTest:0x269e260>

Can you show the calling code?

Kind regards

robert

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

I solved this by using it as public

That is not necessary, since your error was most likely that you
invoked the method with an explicit receiver.

Also another way is to use the variable @__name__

For what?

Kind regards

robert

···

On Mon, Oct 31, 2011 at 3:56 PM, Mario Ruiz <tcblues@gmail.com> wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/