the method is defined as x.greeting, which makes self in it reference the object x - which is the class itself. And since the call to name is with an implicit receiver, self is used. So the call to name is sent to the class object, which returns the class' name (through constant magic the class' name is set to "Customer"). Class.new.class.name is similar in that we get the class of the new object and call it's name method. However, Class.class.name would not give the same result since we'd get the class of the class object, which name is "Class" (because all classes are instances of the class Class).
Hope I could help.
Regards,
Calvin
···
On 11.04.2013 23:08, Sigurd wrote:
Correct me if i'm wrong, but since when ruby 1.9 uses "name" for class name? I always though that it's Class.new.class.name or Class.class.name that gives proper result.
That output doesn't fit the program. Where do lines with "8577108" come
from?
That was a typo. Actually I used in the code `Object_id`. those numbers
are object_id of `Joe`. But during copy -paste I forgot to remove those
numbers. Sorry for that.
Could you give me a valid example? on the below -
eql?(other) → true or false
···
On Thu, Apr 11, 2013 at 4:59 PM, Love U Ruby <lists@ruby-forum.com> > wrote:
It's better to have an intention... a real world use... for example, try to build yourself a text based adventure game... don't just go through all the methods and ask us what they do. You won't learn very well that way, and nothing will stick in your mind.
Julian
···
On 12/04/2013, at 1:14 AM, Love U Ruby <lists@ruby-forum.com> wrote:
Robert Klemme wrote in post #1105270:
On Thu, Apr 11, 2013 at 4:59 PM, Love U Ruby <lists@ruby-forum.com> >> wrote:
1060632465
p joe.hash
-672312861
8577108
-672312861
8577108
That output doesn't fit the program. Where do lines with "8577108" come
from?
That was a typo. Actually I used in the code `Object_id`. those numbers
are object_id of `Joe`. But during copy -paste I forgot to remove those
numbers. Sorry for that.
An alternative way to learn ruby would be to go and do the ruby koans.
Julian
···
On 12/04/2013, at 1:27 AM, Julian Leviston <julian@coretech.net.au> wrote:
The way you're teaching yourself ruby isn't good.
It's better to have an intention... a real world use... for example, try to build yourself a text based adventure game... don't just go through all the methods and ask us what they do. You won't learn very well that way, and nothing will stick in your mind.
Julian
On 12/04/2013, at 1:14 AM, Love U Ruby <lists@ruby-forum.com> wrote:
Robert Klemme wrote in post #1105270:
On Thu, Apr 11, 2013 at 4:59 PM, Love U Ruby <lists@ruby-forum.com> >>> wrote:
1060632465
p joe.hash
-672312861
8577108
-672312861
8577108
That output doesn't fit the program. Where do lines with "8577108" come
from?
That was a typo. Actually I used in the code `Object_id`. those numbers
are object_id of `Joe`. But during copy -paste I forgot to remove those
numbers. Sorry for that.
An alternative way to learn ruby would be to go and do the ruby koans.
Julian
Yes,you are right. Thanks for the suggestions. But I am making myself
educated on each class and the methods of that class. Otherwise I have
seen sometimes I write a complex code to get something,but ruby has a
built function to do that. Thus I think it is good to touch all the
methods at-least. So that wright things can be used at wright time.
Okay, in that case might I suggest for you to build it up yourself with your own self reliance rather than asking questions.
Use IRB *a LOT*, and inspect the hell out of your variables and try to understand things really well. Before you do this process you're undertaking, you might want to read up about Ruby metaprogramming and understand it quite thoroughly at a low and deep level, because the level of questions you're asking are quite clearly outstripping your capability (otherwise you wouldn't have so many questions). Perhaps that's just exacerbated by the Struct class, I'm not sure.
A better way to do this *might* be to *write* some Ruby Koans for yourself and the community, and in the process, you'll be forced to clearly and cleanly understand why and how things do what they do.
I guess you're trying to understand the intent without truly understanding the language at a deep level.
The alternative is you could get and consume (thoroughly) the following books which I think are absolutely excellent. The Ruby Programming Language, The Ruby Way and The Well-Grounded Rubyist.
The reason I suggested real working code is that you need to engage your feelings in the process otherwise things just won't stick in your memory, and stories are more emotive than examples. Stories have more feeling, and real working code involves a story, whereas an example doesn't.
The other thing I'd suggest is to look at the ruby spec. This will give you an unfathomably deep understanding of ruby. IMHO.
Julian
···
On 12/04/2013, at 3:12 AM, Love U Ruby <lists@ruby-forum.com> wrote:
Julian Leviston wrote in post #1105279:
An alternative way to learn ruby would be to go and do the ruby koans.
Julian
Yes,you are right. Thanks for the suggestions. But I am making myself
educated on each class and the methods of that class. Otherwise I have
seen sometimes I write a complex code to get something,but ruby has a
built function to do that. Thus I think it is good to touch all the
methods at-least. So that wright things can be used at wright time.
Whatever "wright time" is. That approach won't work well. You better
search for adequate implementations _when you need them_. Then you can
immediately use them and the learning effect will be much better - unless
you have a photographic memory.
My 0.02 EUR
robert
···
On Thu, Apr 11, 2013 at 7:12 PM, Love U Ruby <lists@ruby-forum.com> wrote:
But I am making myself
educated on each class and the methods of that class. Otherwise I have
seen sometimes I write a complex code to get something,but ruby has a
built function to do that. Thus I think it is good to touch all the
methods at-least. So that wright things can be used at wright time.
The alternative is you could get and consume (thoroughly) the following
books which I think are absolutely excellent. The Ruby Programming
Language, The Ruby Way and The Well-Grounded Rubyist.
I am done with the "The Well-Grounded Rubyist." . As you suggest I will
start now with the other two of-course.
The reason I suggested real working code is that you need to engage your
feelings in the process otherwise things just won't stick in your
memory, and stories are more emotive than examples. Stories have more
feeling, and real working code involves a story, whereas an example
doesn't.
Thanks for writing the above.
The other thing I'd suggest is to look at the ruby spec. This will give
you an unfathomably deep understanding of ruby. IMHO.