Class: Variable
- Inherits:
-
Object
show all
- Defined in:
- lib/chebyruby/variable.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(x) ⇒ Variable
Returns a new instance of Variable.
6
7
8
9
|
# File 'lib/chebyruby/variable.rb', line 6
def initialize(x)
@x = x
@neg = false
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
11
12
13
|
# File 'lib/chebyruby/variable.rb', line 11
def method_missing(method, *args)
Expression.new(self, method, Variable.new(args[0]))
end
|
Instance Attribute Details
#neg ⇒ Object
Returns the value of attribute neg.
4
5
6
|
# File 'lib/chebyruby/variable.rb', line 4
def neg
@neg
end
|
#x ⇒ Object
Returns the value of attribute x.
4
5
6
|
# File 'lib/chebyruby/variable.rb', line 4
def x
@x
end
|
Instance Method Details
#-@ ⇒ Object
23
24
25
|
# File 'lib/chebyruby/variable.rb', line 23
def -@
@neg = true
end
|
#parseable ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/chebyruby/variable.rb', line 39
def parseable
to_enum.map do |i|
if Array === i
i.parseable
elsif Symbol === i
i
else
i.x
end
end
end
|
#right ⇒ Object
31
32
33
|
# File 'lib/chebyruby/variable.rb', line 31
def right
nil
end
|
#to_a ⇒ Object
Also known as:
to_ary
15
16
17
18
19
20
21
|
# File 'lib/chebyruby/variable.rb', line 15
def to_a
if x.class == Array
x
else
[x]
end
end
|
#to_enum ⇒ Object
27
28
29
|
# File 'lib/chebyruby/variable.rb', line 27
def to_enum
Array.new(to_ary).to_enum
end
|
#to_s ⇒ Object
35
36
37
|
# File 'lib/chebyruby/variable.rb', line 35
def to_s
"#{x}"
end
|