Class: Numeric

Inherits:
Object show all
Defined in:
lib/webget_ruby_ramp/numeric.rb

Overview

Numeric extensions

Instance Method Summary collapse

Instance Method Details

#if(flag) ⇒ Object

Returns 0 if the given flag is any of: nil, false, 0, [], {}.

Examples:

3.if(true) => 3
3.if(false) => 0

Returns:

  • 0 if the given flag is any of: nil, false, 0, [], {}



15
16
17
# File 'lib/webget_ruby_ramp/numeric.rb', line 15

def if(flag)
  if [nil,false,0,[],{}].include?(flag) then 0 else self end
end

#unless(flag) ⇒ Object

Returns self if flag is nil, false, 0, [], {}; otherwise return 0.

Examples:

3.unless(true) => 0
3.unless(false) => 3

Returns:

  • self if flag is nil, false, 0, [], {}; otherwise return 0.



26
27
28
# File 'lib/webget_ruby_ramp/numeric.rb', line 26

def unless(flag)
  if [nil,false,0,[],{}].include?(flag) then self else 0 end
end