| Deletions are marked like this. | Additions are marked like this. |
| Line 1: | Line 1: |
| As I'm just learning Ruby, I sometimes need to jog my memory. Perhaps this will be useful to others, too. See the [http://www.ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html manual] or the [http://www.rubycentral.com/book/ book] for more detail. | As I'm just learning Ruby, I sometimes need to jog my memory. Perhaps this will be useful to others, too. See the [[http://www.ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html|manual]] or the [[http://www.rubycentral.com/book/|book]] for more detail. |
| Line 3: | Line 3: |
| [[TableOfContents]] | <<TableOfContents>> |
| Line 6: | Line 6: |
|
* [http://www.zenspider.com/Languages/Ruby/QuickRef.html Ruby QuickRef] * [http://www.glue.umd.edu/~billtj/ruby.html Things That Newcomers to Ruby Should Know] * [http://ruby-pdf.rubyforge.org/pdf-writer/demos/Ruby-Library-QuickRef.pdf Ruby Libarary QuickRef] (2-page PDF) * [http://blog.nanorails.com/pages/rails_1.1_cheat_sheet Rails 1.1 cheat sheet] |
* [[http://www.zenspider.com/Languages/Ruby/QuickRef.html|Ruby QuickRef]] * [[http://www.glue.umd.edu/~billtj/ruby.html|Things That Newcomers to Ruby Should Know]] * [[http://ruby-pdf.rubyforge.org/pdf-writer/demos/Ruby-Library-QuickRef.pdf|Ruby Libarary QuickRef]] (2-page PDF) * [[http://blog.nanorails.com/pages/rails_1.1_cheat_sheet|Rails 1.1 cheat sheet]] |
| Line 27: | Line 27: |
| [http://rubyonwindows.blogspot.com/2007/04/automating-excel-with-ruby-defining.html#comment-3801075022718276883 ref] on [*x] syntax | [[http://rubyonwindows.blogspot.com/2007/04/automating-excel-with-ruby-defining.html#comment-3801075022718276883|ref]] on [*x] syntax |
| Line 71: | Line 71: |
| * Interactive Ruby Interpreter at [http://www.ruby.ch/en/rubymain.shtml Ruby.CHannel] | * Interactive Ruby Interpreter at [[http://www.ruby.ch/en/rubymain.shtml|Ruby.CHannel]] |
As I'm just learning Ruby, I sometimes need to jog my memory. Perhaps this will be useful to others, too. See the manual or the book for more detail.
Contents
Other references
Ruby Libarary QuickRef (2-page PDF)
Variables and constants
FOO # constant $foo # global @@foo # class @foo # instance foo # local
Arrays
a = [ 1, 'cat', 3.14 ] # array with three elements a = [*x] # converts object 'x' to array a = [*1..5] # creates an array filled with the numbers of the range: [1,2,3,4,5]
ref on [*x] syntax
Classes
declaration:
class Foo < Super
BAR = "bar"
def initialize(name) # constructor
@name = name
end
def method0
return @name
end
def method1 (arg1)
super arg1
print arg1
end
def Foo.classMethod arg1
return arg1 * arg1
end
protected
def protected1
print "protected method"
end
private
def private1
print "private method"
end
endaccess:
myvar = Foo::BAR # access constant BAR in class Foo myinstance = Foo.new "myname" whatismyname = myinstance.method0
hints and tools
Interactive Ruby Interpreter at Ruby.CHannel
telling the difference between a string and an array
An array will return true for var.respond_to?("join")
