E
egervari
Question 1
I was curious what ":" before a identifier was exactly. It seems that
it's often used as a map key... but what is it exactly?
Printing :bob to the screen results in "bob"... but testing for
equality between :bob and "bob" results in a falsehood.
I figure this has to be some literal notation for something, but what?
Question 2
In RSpec, it uses == for equality. I overrode the eql?() method in
object, but == doesn't use it. I am used to languages providing an
equals() method that you can override. So if you want 1:1 equals, you
must use eql? and == is just comparing the object id's? So does that
mean that the literal 1 uses the same object no matter where that
literal is used?
It just seems a little weird to me that if everything is an object...
then my assumption would be that == would compare the actual state and
not the object references like it does in Java. Can you clear this up?
Thanks!
Question 3
Ruby seems to @ in front of an identifier to denote that it's an
instance variable. I'm curious, what is the reason for this? And if
these variables are in fact private to the object, is there some kind
of short-hand to create getter/setters?, or do you have to define
these 2 def's yourself? I guess if that's the case, it's no worse than
in Java, but Scala provides several ways to get around this. I'm
curious if such shorthands exist.
Thanks!
I was curious what ":" before a identifier was exactly. It seems that
it's often used as a map key... but what is it exactly?
Printing :bob to the screen results in "bob"... but testing for
equality between :bob and "bob" results in a falsehood.
I figure this has to be some literal notation for something, but what?
Question 2
In RSpec, it uses == for equality. I overrode the eql?() method in
object, but == doesn't use it. I am used to languages providing an
equals() method that you can override. So if you want 1:1 equals, you
must use eql? and == is just comparing the object id's? So does that
mean that the literal 1 uses the same object no matter where that
literal is used?
It just seems a little weird to me that if everything is an object...
then my assumption would be that == would compare the actual state and
not the object references like it does in Java. Can you clear this up?
Thanks!
Question 3
Ruby seems to @ in front of an identifier to denote that it's an
instance variable. I'm curious, what is the reason for this? And if
these variables are in fact private to the object, is there some kind
of short-hand to create getter/setters?, or do you have to define
these 2 def's yourself? I guess if that's the case, it's no worse than
in Java, but Scala provides several ways to get around this. I'm
curious if such shorthands exist.
Thanks!