summaryrefslogtreecommitdiffhomepage
path: root/ruby.html.markdown
diff options
context:
space:
mode:
Diffstat (limited to 'ruby.html.markdown')
-rw-r--r--ruby.html.markdown22
1 files changed, 14 insertions, 8 deletions
diff --git a/ruby.html.markdown b/ruby.html.markdown
index 2c9a4cb9..38d060a3 100644
--- a/ruby.html.markdown
+++ b/ruby.html.markdown
@@ -43,17 +43,18 @@ false.class #=> FalseClass
1 == 1 #=> true
2 == 1 #=> false
-# apart from false itself, nil is the only other 'falsey' value
-
-nil == false #=> true
-0 == false #=> false
-
# Inequality
1 != 1 #=> false
2 != 1 #=> true
!true #=> false
!false #=> true
+# apart from false itself, nil is the only other 'falsey' value
+
+!nil #=> true
+!false #=> true
+!0 #=> false
+
# More comparisons
1 < 10 #=> true
1 > 10 #=> false
@@ -194,6 +195,7 @@ end
counter = 1
while counter <= 5 do
puts "iteration #{counter}"
+ counter += 1
end
#=> iteration 1
#=> iteration 2
@@ -214,7 +216,9 @@ when 'D'
puts "Scraping through"
when 'F'
puts "You failed!"
-
+else
+ puts "Alternative grading system, eh?"
+end
# Functions
@@ -263,7 +267,7 @@ class Human
@@species = "H. sapiens"
# Basic initializer
- def initialize(name, age=0):
+ def initialize(name, age=0)
# Assign the argument to the "name" instance variable for the instance
@name = name
# If no age given, we will fall back to the default in the arguments list.
@@ -281,7 +285,7 @@ class Human
end
# A class method uses self to distinguish from instance methods.
- $ It can only be called on the class, not an instance.
+ # It can only be called on the class, not an instance.
def self.say(msg)
puts "#{msg}"
end
@@ -301,6 +305,8 @@ dwight = Human.new("Dwight K. Schrute")
# Let's call a couple of methods
jim.species #=> "H. sapiens"
jim.name #=> "Jim Halpert"
+jim.name = "Jim Halpert II" #=> "Jim Halpert II"
+jim.name #=> "Jim Halpert II"
dwight.species #=> "H. sapiens"
dwight.name #=> "Dwight K. Schrute"