Class: Eletro::Part
- Inherits:
-
Object
show all
- Defined in:
- lib/eletro/part.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/eletro/part.rb', line 49
def method_missing(*args)
txt = args.join
if txt =~ /p\d+/
if txt =~ /=/
var, value = txt.split("=")
instance_variable_set("@#{var}", value)
self.class.instance_eval do
define_method(var, lambda { instance_variable_get("@#{var}") })
end
else
respond_to?(txt) ? send(args.join) : nil
end
else
super
end
end
|
Instance Attribute Details
#i ⇒ Object
Returns the value of attribute i.
4
5
6
|
# File 'lib/eletro/part.rb', line 4
def i
@i
end
|
#p0 ⇒ Object
Returns the value of attribute p0.
4
5
6
|
# File 'lib/eletro/part.rb', line 4
def p0
@p0
end
|
#p1 ⇒ Object
Returns the value of attribute p1.
4
5
6
|
# File 'lib/eletro/part.rb', line 4
def p1
@p1
end
|
#unit ⇒ Object
Returns the value of attribute unit.
4
5
6
|
# File 'lib/eletro/part.rb', line 4
def unit
@unit
end
|
#v ⇒ Object
Returns the value of attribute v.
4
5
6
|
# File 'lib/eletro/part.rb', line 4
def v
@v
end
|
#value ⇒ Object
Returns the value of attribute value.
4
5
6
|
# File 'lib/eletro/part.rb', line 4
def value
@value
end
|
Instance Method Details
#*(other) ⇒ Object
14
15
16
|
# File 'lib/eletro/part.rb', line 14
def *(other)
self.class.new(self.value*other)
end
|
#+(other) ⇒ Object
18
19
20
|
# File 'lib/eletro/part.rb', line 18
def +(other)
self.class.new(self.value+other)
end
|
#-(other) ⇒ Object
26
27
28
|
# File 'lib/eletro/part.rb', line 26
def -(other)
self.class.new(self.value-other)
end
|
#/(other) ⇒ Object
22
23
24
|
# File 'lib/eletro/part.rb', line 22
def /(other)
self.class.new(self.value/other)
end
|
#abs ⇒ Object
30
31
32
|
# File 'lib/eletro/part.rb', line 30
def abs
self.value.abs
end
|
#coerce(other) ⇒ Object
43
|
# File 'lib/eletro/part.rb', line 43
def coerce(other); [other, @value]; end
|
#round ⇒ Object
45
46
47
|
# File 'lib/eletro/part.rb', line 45
def round
end
|
#to_f ⇒ Object
34
|
# File 'lib/eletro/part.rb', line 34
def to_f; @value; end
|
#to_i ⇒ Object
35
|
# File 'lib/eletro/part.rb', line 35
def to_i; @value.to_i; end
|
#to_s ⇒ Object
38
39
40
|
# File 'lib/eletro/part.rb', line 38
def to_s
"#{@value}#{unit}"
end
|