This link has been bookmarked by 39 people . It was first bookmarked on 16 Aug 2008, by A. D..
-
12 Jan 12
-
24 Sep 11
-
08 Jun 11
-
19 Dec 10
-
06 Oct 10
thattommyhallSimilarly, methods are also Objects in the making:
method(:puts).call "puts is an object!"
# => puts is an object! -
25 Jul 10
-
07 Jul 10
-
For any given two Symbols that represent the same characters, the
object_ids match. -
Whenever you use a new String, Ruby allocates memory for it.
-
consider what’s more important: the identity of an object (i.e. a Hash key), or the contents (in the example above, “george”).
-
Ruby enforces some naming conventions. If an identifier starts with a capital letter, it is a constant. If it starts with a dollar sign ($), it is a global variable. If it starts with
@, it is an instance variable. If it starts with@@, it is a class variable. -
Ruby doesn’t have keyword parameters, like Python has. However, it can be faked by using symbols and hashes. Ruby on Rails, among others, uses this heavily.
-
You might expect
another_methodto be public. Not so. The ‘private’ access modifier continues until the end of the scope, or until another access modifier pops up, whichever comes first. -
privatemeans the method(s) are accessible only when they can be called without an explicit receiver. -
rotectedis the one to be on the lookout for. A protected method can be called from a class
-
-
27 Apr 10
-
11 Mar 10
-
21 Jan 10
-
10 Jan 10
-
21 Dec 09
-
18 Dec 09
-
25 Sep 09
-
If you’re in doubt whether to use a Symbol or a String, consider what’s more important: the identity of an object (i.e. a Hash key), or the contents (in the example above, “george”).
-
# This is the same as
# class MyClass
# attr_accessor :instance_var
# end
MyClass = Class.new do
attr_accessor :instance_var
end -
If an identifier starts with a capital letter, it is a constant. If it starts with a dollar sign ($), it is a global variable. If it starts with
@, it is an instance variable. If it starts with@@, it is a class variable. -
In Ruby, everything except nil and false is considered true.
-
public,privateandprotectedare really methods, so they can take parameters. -
privatemeans the method(s) are accessible only when they can be called without an explicit receiver. Only self is allowed to be the receiver of a private method call. -
A protected method can be called from a class or descendant class instances, but also with another instance as its receiver.
-
Ruby on Rails defines a bunch of methods for dealing with time on
Fixnum. -
Potentially “dangerous” methods (ie methods that modify self or the arguments,
exit!etc.) by convention end with exclamation marks. -
Singleton methods are per-object methods.
-
method_missing
-
# This
1 + 2
# Is the same as this ...
1.+(2)
# Which is the same as this:
1.send "+", 2 -
Blocks are Objects
-
To define the unary + and – (think +1 and -2), you must define the
+@and-@methods, respectively.
-
-
12 Aug 09
-
18 Jul 09
-
Iteration
-
Everything has a value
-
Symbols can best be described as identities. A symbol is all about who it is, not what it is.
-
Constants are not really constant. If you modify an already initialized constant, it will trigger a warning, but not halt your program. That isn’t to say you should redefine constants, though
-
Ruby enforces some naming conventions. If an identifier starts with a capital letter, it is a constant. If it starts with a dollar sign ($), it is a global variable. If it starts with
@, it is an instance variable. If it starts with@@, it is a class variable. -
In Ruby, everything except nil and false is considered true
-
Access modifiers apply until the end of scope
-
protectedis the one to be on the lookout for. A protected method can be called from a class or descendant class instances, but also with another instance as its receiver. -
Ruby classes are open. You can open them up, add to them, and change them at any time.
-
Singleton methods are per-object methods. They are only available on the Object you defined it on
-
Ruby doesn’t give up if it can’t find a method that responds to a particular message. It calls the
method_missingmethod with the name of the method it couldn’t find and the arguments -
A method call is really a message to another object:
-
-
19 Nov 08
-
16 Aug 08
-
20 May 08
-
16 Jan 08
-
20 Oct 07
-
03 Mar 07
-
11 Feb 07
-
01 Dec 06
-
27 Nov 06
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.