This file contains 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 | |
def initialize(name) | |
@name = name | |
end | |
def bark | |
puts "#{@name} says woof!" | |
end | |
def eat |
This file contains 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 | |
def initialize(name) | |
@name = name | |
end | |
def bark | |
'woof!' | |
end | |
def eat |
This file contains 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 | |
def initialize(name) | |
@name = name | |
end | |
def bark | |
'woof!' | |
end | |
def eat |
This file contains 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
module UnpredictableString | |
def scramble | |
self.split(//).shuffle.join | |
end | |
end | |
class String | |
include UnpredictableString | |
end | |
This file contains 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 String | |
def self.scramble | |
"this is an example".split(//).shuffle.join | |
end | |
end | |
puts String.scramble |
This file contains 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 | |
def initialize string | |
@self_badname = string | |
end | |
def scramble | |
@self_badname.split(//).shuffle.join | |
end | |
def to_s |
This file contains 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 initialize name | |
@name = name | |
end | |
def rotate(rotation_type) | |
"#{@name} is rotating around #{rotation_type}" | |
end | |
def play_sound(format) | |
"#{@name} is playing file #{@name}.#{format}" | |
end |
This file contains 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 rotate | |
'Rotating around the center of ' + self.class.name | |
end | |
def play_sound | |
"I am playing the sound #{self.class.name}.aif" | |
end | |
end |
This file contains 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 GameBoard | |
def initialize | |
@range = [0,1,2,3,4,5,6] | |
@no_of_hits = 0 | |
end | |
def set_locations_cells(locations) | |
@numbers_to_guess = [] | |
locations.each{|index| @numbers_to_guess.push(@range[index])} | |
end |
This file contains 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
# simple_repl.rb | |
# This program replicate a very simple REPL for Ruby. | |
def prompt | |
print '>>' | |
user_input = gets.chomp! | |
puts("=> #{eval(user_input)}") | |
end | |
loop do | |
prompt |
OlderNewer