Skip to content

Instantly share code, notes, and snippets.

@joshbuddy
Created June 17, 2011 18:33
Show Gist options
  • Save joshbuddy/1031992 to your computer and use it in GitHub Desktop.
Save joshbuddy/1031992 to your computer and use it in GitHub Desktop.
class Song
def initialize(title, length_in_seconds, author)
@title, @length_in_seconds, @author = title, length_in_seconds, author
end
# real ruby
def length_in_minutes
@length_in_seconds.to_f / 60
end
def to_s
"#{@title} (#{@author})"
end
# fake ruby
def length_in_minutes = @length_in_seconds.to_f / 60
def to_s = "#{@title} (#{@author})"
end
@achiurizo
Copy link

isn't #define_method sort of like that?

define_method(:length_in_minutes) { @length_in_seconds.to_f / 60 }
# faker ruby
def(:length_in_minutes) { @length_in_seconds.to_f / 60 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment