Afficher un message
Vieux 12/03/2008, 20h59   #3
Daniel Brumbaugh Keeney
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: a method that checks if an object is in a range

On Wed, Mar 12, 2008 at 12:59 PM, <wojtek@m4chu.net> wrote:
> Hi,
>
> I wonder if there is a built-in method which does just like:
>
> range.include?(obj)
>
> but for the obj object. I came up with something like:
>
> module Comparable
> def in?(range)
> range.in?(self)
> end
> end
>
> 1.in? (1..10) # => true
>
> Of course I can use the range.include? syntax, but I find the second
> approach more convenient
>
> Regards,
> m4chu


I personally am not a fan of such methods, but perhaps
Comparable#between will satisfy you.

Daniel Brumbaugh Keeney

  Réponse avec citation
 
Page generated in 0,05136 seconds with 9 queries