Last active
September 11, 2016 10:35
-
-
Save peco8/e6067f5d40f22c6a85adda82f6c41170 to your computer and use it in GitHub Desktop.
# 2 Use built-in conversion protocols
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
winners = [ | |
'HomeStar', | |
'King of town', | |
'Marzipan', | |
'Strongpad' | |
] | |
Place = Struct.new(:index, :name, :prize) | |
first = Place.new(0, 'first', 'Peasants quest game') | |
second = Place.new(1, 'second', 'pockemon') | |
third = Place.new(2, 'third', 'ff') | |
[first, second, third].each do |place| | |
puts "In #{place.name} place, #{winners[place.index]}" | |
puts "You win: #{place.prize}" | |
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
# Place is more or less just an index with some metadata, it would be cool if we could use it as an index by itself. | |
winners = [ | |
'HomeStar', | |
'King of town', | |
'Marzipan', | |
'Strongpad' | |
] | |
Place = Struct.new(:index, :name, :prize) do |place| | |
def to_int | |
index | |
end | |
end | |
first = Place.new(0, 'first', 'Peasants quest game') | |
second = Place.new(1, 'second', 'pockemon') | |
third = Place.new(2, 'third', 'ff') | |
[first, second, third].each do |place| | |
puts "In #{place.name} place, #{winners[place]}" | |
puts "You win: #{place.prize}" | |
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 EmacsConfigFile | |
def initialize | |
@filename = "#{ENV['HOME']}/.vimrc" | |
end | |
def to_path | |
@filename | |
end end | |
emacs_config = EmacsConfigFile.new | |
File.open(emacs_config).lines.count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment