Class: Numeric

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

Instance Method Summary collapse

Instance Method Details

#centiObject

Return self * 10^2



74
75
76
# File 'lib/webget_ramp/numeric.rb', line 74

def centi
 self*100
end

#deciObject

Return self * 10



69
70
71
# File 'lib/webget_ramp/numeric.rb', line 69

def deci
 self*10
end

#dekaObject

Return self / 10



64
65
66
# File 'lib/webget_ramp/numeric.rb', line 64

def deka
 self/10
end

#gigaObject

Return self / 10^9



44
45
46
# File 'lib/webget_ramp/numeric.rb', line 44

def giga
 self/1000000000
end

#hectoObject

Return self / 10^2



59
60
61
# File 'lib/webget_ramp/numeric.rb', line 59

def hecto
 self/100
end

#if(flag) ⇒ Object

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

This is useful for multiplying a number if and only if a flag is set.

Example

sum = x.if(foo) + y.if(bar)


11
12
13
# File 'lib/webget_ramp/numeric.rb', line 11

def if(flag)
 (flag==nil or flag==false or flag==0 or flag==[] or flag=={}) ? 0 : self
end

#kiloObject

Return self / 10^3



54
55
56
# File 'lib/webget_ramp/numeric.rb', line 54

def kilo
 self/1000
end

#megaObject

Return self / 10^6



49
50
51
# File 'lib/webget_ramp/numeric.rb', line 49

def mega
 self/100000
end

#microObject

Return self * 10^6



84
85
86
# File 'lib/webget_ramp/numeric.rb', line 84

def micro
 self*1000000
end

#milliObject

Return self * 10^3



79
80
81
# File 'lib/webget_ramp/numeric.rb', line 79

def milli
 self*1000
end

#nanoObject

Return self * 10^9



89
90
91
# File 'lib/webget_ramp/numeric.rb', line 89

def nano
 self*1000000000
end

#petaObject

Return self / 10^15



34
35
36
# File 'lib/webget_ramp/numeric.rb', line 34

def peta
 self/1000000000000000
end

#teraObject

Return self / 10^12



39
40
41
# File 'lib/webget_ramp/numeric.rb', line 39

def tera
 self/1000000000000
end

#unless(flag) ⇒ Object

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

This is useful for multiplying a number if and only if a flag is unset.

Example

sum = w.unless(foo) +y.unless(bar)


23
24
25
# File 'lib/webget_ramp/numeric.rb', line 23

def unless(flag)
 (flag==nil or flag==false or flag==0 or flag==[] or flag=={}) ? self : 0
end