lib/danica/wrapper/constant.rb in danica-2.4.1 vs lib/danica/wrapper/constant.rb in danica-2.4.2
- old
+ new
@@ -7,14 +7,17 @@
default_value :priority, 10
default_value :valued?, true
default_value :is_grouped?, false
- def initialize(value, latex, gnu)
- @value = value
- @latex = latex
- @gnu = gnu
+ def initialize(*args)
+ attrs = args.extract_options!
+ attrs = args.as_hash(%i(value latex gnu)).merge(attrs)
+
+ attrs.each do |key, value|
+ self.send("#{key}=", value)
+ end
end
def to_f
value.to_f
end
@@ -28,9 +31,23 @@
latex.to_s
end
def to_gnu
gnu.to_s
+ end
+
+ private
+
+ def value=(value)
+ @value = value
+ end
+
+ def latex=(latex)
+ @latex = latex
+ end
+
+ def gnu=(gnu)
+ @gnu = gnu
end
end
E = Wrapper::Constant.new(Math::E, :e, 'exp(1)')
PI = Wrapper::Constant.new(Math::PI, '\pi', :pi)