From: Stefano Crocco Date: 2013-02-23T17:02:38+09:00 Subject: Re: Why class returning its own name when "include" statement? On Saturday 23 February 2013 Love U Ruby wrote > I was actually playing around with the class definition return values. > below is the all IRB code that I used till now. > > module Show > def show_string > p "hi" > end > end > > #=> nil > class Test > include Show > def show_line > p "I am a boy" > end > end > #=> nil > > class Abc > end > #=> nil > class Bbc > @X=10 > end > #=> 10 > class Test123 > include Show > @x=5 > end > #=> 5 > > ========================================================================= > Till the above code I did understand the logic,but in the below code why > "class" definition returns its own name whenever "include" is the last > statement? - I didn't understand this fact. > ========================================================================= > > class Foo > @x=12 > include Show > end > #=> Foo > > > class Test > include Show > end > #=> Test > > -- > Posted via http://www.ruby-forum.com/. As you can see from your Abc example, a class expression returns the value of the last expression inside it. Since Module#include returns self (that is, the caller which, in your case, is class Foo), the whole class expression returns the class itself (not its name, but the class object). Stefano