Skip to content

Instantly share code, notes, and snippets.

@micahbrich
Forked from adgilfillan/Pitchersssss
Last active December 17, 2015 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micahbrich/5550095 to your computer and use it in GitHub Desktop.
Save micahbrich/5550095 to your computer and use it in GitHub Desktop.
class Pitcher
attr_accessor :whip, :age
alias :whip_1 :whip
(2..20).each do |num|
define_method("whip_#{num}") do
if self.age < 28
eval("self.whip_#{num-1}") * 0.95
else
eval("self.whip_#{num-1}") * 1.05
end
end
end
end
@pitcher = Pitcher.new
@pitcher.whip, @pitcher.age = 1, 32
(1..20).each do |num|
result = eval("@pitcher.whip_#{num}")
puts "@pitcher.whip_#{num} = #{result}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment