On Wed, Feb 27, 2013 at 2:36 PM, Love U Ruby <[email protected]> wrote:
> CODE - I
>
> class Fixnum
> alias other_s to_s
> def to_s
> a = self + 5
> return a.other_s
> end
> end
> #=> nil
> puts 5
> 10
> #=> nil
>
> CODE - II
>
> class Fixnum
> alias other_s to_s
> def to_s
> self + 5
> #return a.other_s
> end
> end
>
> puts 5
> #<Fixnum:0x00000b>
> #=> nil
>
> What I know that block returns automatically its last expression. Why
> does `10` not the returned
> here, rather `#<Fixnum:0x00000b>`?
>
> But with the `return a.other_s` `10` printed - what is the concpetual
> difference between CODE-I and CODE - II?

Come on, that's really simple: You do not invoke #other_s.

robert


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

-- 
[email protected] | 
https://groups.google.com/d/forum/ruby-talk-google?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"ruby-talk-google" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to