Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sayGoodnight(name)
- return "Goodnight, " + name
- end
- def otherWayToSayGoodnight(name)
- "Goodnight, #{name}"
- end
- puts sayGoodnight("John-Boy")
- puts otherWayToSayGoodnight("Richard")
- a = [1, 'cat', 42]
- # Set second item to dog
- a[1] = 'dog'
- # Write it
- puts a[1]
- a = %w(ant bee cat dog elk)
- # Print item 3
- puts a[2]
- # Hash
- fruits = {
- 'apple' => 'red',
- 'pear' => 'green',
- 'banana' => 'yellow',
- }
- puts "Which color is an apple? I guess it's #{fruits['apple']}"
- # Give N a value
- n = 3.14
- # Play with N
- if n > 2
- puts "N is higher than 2"
- elsif n > 900
- puts "N is over 9000!"
- else
- puts "Either N is lower than 2, or not a number!"
- end
- n = 1
- # While loop, 3 times
- while n <= 3
- puts "N is #{n}"
- n += 1
- end
- # Statement modifer
- puts "N is now over 3" if n > 3
- puts "N is in fact #{n}"
Add Comment
Please, Sign In to add comment