Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 2 Use built-in conversion protocols
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
# 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
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