This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = 'key=value' | |
array = s.split("=") | |
s1 = array[0] | |
s2 = array[1] | |
puts s1 | |
puts s2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def method | |
a = 50 | |
puts a | |
end | |
a = 10 | |
method # calls method with local variable a = 50, then puts local varaible | |
puts a # puts the global variable a = 10 from line 6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1929 | |
1951 | |
1952 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dog | |
attr_accessor :name | |
def bark | |
"#@name barks" | |
end | |
def eat | |
"#@name eats" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rectangle | |
attr_reader :area, :perimeter | |
def initialize(width, height) | |
@area = width * height | |
@perimeter = (width + height)*2 | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UnpredictableString < String | |
def scramble | |
self.split("").shuffle.join("") | |
end | |
end | |
sentence = UnpredictableString.new("It was a dark and stormy night.") | |
puts sentence | |
puts sentence.scramble |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Shape | |
def click | |
puts rotate | |
puts play | |
end | |
def play | |
sound | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
attr_accessor :balance | |
Inf = 1.0/0.0 | |
def balance_test | |
puts "Your balance measurement is: #@balance" | |
case balance | |
when 500...Inf | |
"You could be a gymnast" | |
when 100...500 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Shape | |
def click | |
p rotate | |
play | |
end | |
def play | |
sound | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UnpredictableString < String | |
def scramble(string) | |
string.split("").shuffle.join("") | |
end | |
end | |
sentence = UnpredictableString.new | |
p sentence.scramble("It was a dark and stormy night.") |