Why class returning its own name when "include" statement?

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

On Saturday 23 February 2013 Love U Ruby wrote

class Test
class Bbc
Till the above code I did understand the logic,but in the below code why

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

@Stefano Yes you are right. The below code is proved that.


module Show
def show_string
p “hi”
end
end

=> nil

class Foo
@x=12
(include Show).object_id
end

=> 10681980

class Too
@x=12
(include Show).object_id.inspect
end

=> “10648020”


Does that mean @x has been already initialized? or curious to know what
“10648020” contains into it?

On Feb 23, 2013 2:21 AM, “Love U Ruby” [email protected] wrote:

class Foo

Does that mean @x has been already initialized? or curious to know what
“10648020” contains into it?

@x is set inside the class and will be set thus when Foo.new or Too.new
is
called. Each such object will have its own copy of @x.

The number in quotes is the inspected object id of the included Show
module
instance.

Can anyone help me with my above question please?

tamouse mailing lists wrote in post #1098808:

On Feb 23, 2013 2:21 AM, “Love U Ruby” [email protected] wrote:

class Foo

Does that mean @x has been already initialized? or curious to know what
“10648020” contains into it?

@x is set inside the class and will be set thus when Foo.new or Too.new
is
called. Each such object will have its own copy of @x.

The number in quotes is the inspected object id of the included Show
module
instance.

not sure about your statement. seems @ Stefano statement contradicts
with you.

Can it be more specific what you meant to say?

tamouse mailing lists wrote in post #1098812:

On Feb 24, 2013 11:05 AM, “Love U Ruby” [email protected] wrote:

called. Each such object will have its own copy of @x.

They are not inconsistent at all. In each,the result of the last
expression
evaluated is returned. In the last case, you evaluated (include
Show).object_id.inspect, didn’t you?

Yes, I did to see, if object created at the “include” time or not. And
it shows “yes” the object created at class definition time.

Then my above list mentioned questions came into my mind.

Thanks

On Feb 24, 2013 11:05 AM, “Love U Ruby” [email protected] wrote:

called. Each such object will have its own copy of @x.

The number in quotes is the inspected object id of the included Show
module
instance.

not sure about your statement. seems @ Stefano statement contradicts
with you.

Can it be more specific what you meant to say?

They are not inconsistent at all. In each,the result of the last
expression
evaluated is returned. In the last case, you evaluated (include
Show).object_id.inspect, didn’t you?

On 25/02/2013, at 8:38 AM, [email protected] wrote:

After that, choose a programming project to work on, something
with a purpose. Then ask questions about how to achieve your goal.

Sounds to me like he/she is trying to write a ruby implementation.

Henry

Am 23.02.2013 09:20, schrieb Love U Ruby:

@x=12
Does that mean @x has been already initialized? or curious to know what
“10648020” contains into it?

It’s useless to ask these kind of “academic”, pointless questions as
long as you do not even have the most basic knowledge about how to
properly define a class with an instance variable.

Read for example this:

http://pine.fm/LearnToProgram/

Read it from beginning to end, do all the exercises.

After that, choose a programming project to work on, something
with a purpose. Then ask questions about how to achieve your goal.

On Feb 24, 2013, at 12:39, Henry M. [email protected] wrote:

On 25/02/2013, at 8:38 AM, [email protected] wrote:

After that, choose a programming project to work on, something
with a purpose. Then ask questions about how to achieve your goal.

Sounds to me like he/she is trying to write a ruby implementation.

Very very poorly in the most annoying and least accurate way possible.

I do wish we’d collectively stop responding to our latest Illias.

On Sun, Feb 24, 2013 at 2:45 PM, Ryan D. [email protected]
wrote:

I do wish we’d collectively stop responding to our latest Illias.

Well, okay, if that’s how others feel, as well.

I do wish we’d collectively stop responding to our latest Illias.

Well, okay, if that’s how others feel, as well.

It is true. :slight_smile:

He is Illias 2.0

Ryan D. wrote in post #1098842:

On Feb 24, 2013, at 12:39, Henry M. [email protected] wrote:

On 25/02/2013, at 8:38 AM, [email protected] wrote:

I do wish we’d collectively stop responding to our latest Illias.

What happened Ryan with you ? Why are you forcing others to believe your
thought about me?

This way nothing gonna be helpful. please don’t do that.

People who has knowledge, no way you can’t stop them to share it.
Because knowledge sharing has some innate proudest within it. If you
don’t like answers to the conceptual questions, only programming type of
questions get yourself busy on that. Don’t need to look into the
question who is asking conceptual things.

As to get into and discover concept from the existing one is another
kind of fascination I think.

Someone might read Array#[] the way it has been documented, But I love
to think beyond that. And If there I feel I need a bit help to move
forward I asked here. Why you think this is for only my personal use
only. Every new started should think this way and If they got stuck can
take my ones as their references.

If I ask only software development specific questions then it would
might be helpful for part of ruby users but the conceptual questions are
for all.

Again If you feel bad, please don’t need to answer my ones,but
requesting you also to that don’t say others to follow you.

Try to understand your weight.

Thanks

Love U Ruby wrote in post #1098555:
@Stefano Yes you are right. The below code is proved that.


module Show
def show_string
p “hi”
end
end

=> nil

class Foo
@x=12
(include Show).object_id
end

=> 10681980

class Too
@x=12
(include Show).object_id.inspect
end

=> “10648020”


As here I didn’t create any object of Too and Foo,then how does such
object number come ?

The group has collectively informed you that you will no longer be
answered for any further questions. This decision was made based upon
your
inability to follow directions, your willful lack at attempting to
learn,
your seemingly willful disregard for using ANY of the tutorials, URLs,
or
other educational material provided to you, and your clear disregard of
instructions not to use the mailing list for every single solitary
thought
that crosses through your mind, as well as your willful disregard for
Googling and learning on your own.

You have zero purpose, you have zero willingness to self educate and
study, and zero willingness to work within the confines of the group’s
requirements which is to study, self educate, try, retry, play around
with
various code and compare your results to known documentation (of which
there is plenty, both that provided by us to you, and that which Google
provides (not to mention ruby-lang.org)).

Your failure to follow our most basic tenants has resulted in us
collectively refusing to answer any further questions that you submit. I
suggest you quit posting for awhile and do some real studying and some
real thinking on proper etiquette and usage of mailing lists. You will
find the same response given on all Ruby related mailing lists from this
point forward.

You did this to yourself.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs