Re: ruby way to say this?

From: Louis J Scoras [mailto:[email protected]]

So your original would look like:

# if_zero(one_thing, other_thing)

Let’s make that more OO-pretty (using a goofy name):

class Numeric
def or_if_zero( alternate_value )
self.nonzero? ? self : alternate_value
end
end

Which makes the code:

oneThing().or_if_zero( otherThing() )

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs