Class: Object

Inherits:
BasicObject
Defined in:
lib/transparent_nil/object.rb

Instance Method Summary collapse

Instance Method Details

#to_nil_if(condition = :empty) ⇒ nil, self

Returns nil if the condition is true. Otherwise self.

Parameters:

  • condition (Symbol) (defaults to: :empty)

Returns:

  • (nil, self)


17
18
19
20
# File 'lib/transparent_nil/object.rb', line 17

def to_nil_if(condition = :empty) 
    return nil         if self.respond(condition.to_s + '?')
    return self
end

#to_nil_unless(condition = :empty) ⇒ nil, self

Returns nil if the condition is true. Otherwise self.

Parameters:

  • condition (Symbol) (defaults to: :empty)

Returns:

  • (nil, self)


25
26
27
28
# File 'lib/transparent_nil/object.rb', line 25

def to_nil_unless(condition = :empty) 
    return nil         unless self.respond(condition.to_s + '?')
    return self
end