On Thu, Jan 23, 2014 at 9:14 AM, Arup Rakshit <lists / ruby-forum.com> wrote:
> Look at the below code :
>
> irb(main):001:0> 2.class
> => Fixnum
> irb(main):002:0> 2.class.included_modules
> => [Comparable, Kernel]
> irb(main):003:0> 2.class.methods.grep /loop/
> => []
> irb(main):004:0> 2.class.instance_methods.grep /loop/
> => []
> irb(main):005:0> 2.class.private_instance_methods.grep /loop/
> => [:loop]
> irb(main):013:0> class Fixnum
> irb(main):014:1>   def show
> irb(main):015:2>      loop
> irb(main):016:2>   end
> irb(main):017:1> end
> => nil

That does not make much sense because loop wants a block.

> irb(main):018:0> 2.loop
> NoMethodError: private method `loop' called for 2:Fixnum
>         from (irb):18
>         from C:/Ruby193/bin/irb:12:in `<main>'
> irb(main):019:0>
>
> On the top level we can call `loop` method, but why not the same way
> inside the method `show` ?

You are not invoking it inside #show, you are invoking it directly.
And you cannot call it with a receiver because it is defined private
in Kernel:

irb(main):001:0> method :loop
=> #<Method: Object(Kernel)#loop>
irb(main):002:0> Kernel.private_instance_methods(false).grep /loop/
=> [:loop]

Btw, there is Fixnum#times if you want to loop as many times as the
number indicates.

Kind regards

robert

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