Skip to content

Instantly share code, notes, and snippets.

@evanphx
Created July 24, 2013 16:31
Show Gist options
  • Save evanphx/6072176 to your computer and use it in GitHub Desktop.
Save evanphx/6072176 to your computer and use it in GitHub Desktop.
class Minutes
def initialize(count)
@count = count
end
def to_i
@count
end
def +(o)
Minutes.new(@count + o.to_i)
end
def -(o)
Minutes.new(@count - o.to_i)
end
def *(o)
Minutes.new(@count * o.to_i)
end
def /(o)
Minutes.new(@count / o.to_i)
end
def coerce(x)
[Minutes.new(@count), Minutes.new(x.to_i)]
end
attr_reader :count
end
m = Minutes.new(5)
p(m + 8)
p(m - 2)
p(m * 2)
p(m / 2)
@adkron
Copy link

adkron commented Jul 24, 2013

Is it normal to call the new again on the lhs in coerce? I usually put self there.

@evanphx
Copy link
Author

evanphx commented Jul 24, 2013

Oh yeah, should be self there.

@adkron
Copy link

adkron commented Jul 24, 2013

Didn't know if I was missing something that would blow my mind. BTW, I've wanted to thank you for a while. Thanks for getting my friend an interpreter for RubyConf last year. He had the best time.

@evanphx
Copy link
Author

evanphx commented Jul 24, 2013

No problem! Glad it worked out. Do you know if he's planning on coming to RubyConf this year?

@adkron
Copy link

adkron commented Jul 24, 2013

I have no idea. I'll ask him right now.

@evanphx
Copy link
Author

evanphx commented Jul 24, 2013

K. hit me back up on twitter when you find out.

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