Permalink
Browse files

New Pages added to the Ruby Primer

Updates made to fix my bugs in the custom_user_welcome_messages file
New code sample to view how looping and conditions work in Ruby
  • Loading branch information...
1 parent a19c557 commit 41f67534d1162b4459ac0c1e503a2590cdd8e198 @newfront committed Nov 3, 2010
View
BIN a_ruby_primer/A Ruby Primer.docx
Binary file not shown.
View
8 rails_primer_code/custom_user_welcome_messages_5-1-5.rb
@@ -16,15 +16,15 @@ def initialize(username,level)
def greet_me
message = case
- when 1 then "Welcome #{@@username}, click here to view our tour"
- when 2 then "Welcome Back! #{@@username}"
- when 3 then "Welcome Super-User #{@username}. We love you"
+ when @@user_level == 1 then "Welcome #{@@username}, click here to view our tour"
+ when @@user_level == 2 then "Welcome Back! #{@@username}"
+ when @@user_level == 3 then "Welcome Super-User #{@@username}. We love you"
else "You are not registered yet, or we screwed up our code"
end
puts message
@@message = message
end
end
-n = SayHello.new("Scott",3)
+n = SayHello.new("Scott",2)
n.greet_me
View
19 rails_primer_code/looping_and_conditions_5-2-2.rb
@@ -0,0 +1,19 @@
+#!/usr/bin/ruby -w
+
+# = Looping with Conditions
+
+@target = 25
+
+@ages = [10,12,24,35,46,25,19,18,31]
+
+# Loop through the @ages Array
+
+for @i in 0..@ages.length do
+ #check to see if the current Array Element is equal to our target
+ if @ages[@i] == @target
+ puts "Excellent. These conditions have been met"
+ break
+ else
+ puts "Still waiting for my conditions to be met"
+ end
+end

0 comments on commit 41f6753

Please sign in to comment.