Method: Writeexcel::Format#method_missing
- Defined in:
- lib/writeexcel/format.rb
#method_missing(name, *args) ⇒ Object
Dynamically create set methods that aren’t already defined.
1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 |
# File 'lib/writeexcel/format.rb', line 1544 def method_missing(name, *args) # :nodoc: # -- original perl comment -- # There are two types of set methods: set_property() and # set_property_color(). When a method is AUTOLOADED we store a new anonymous # sub in the appropriate slot in the symbol table. The speeds up subsequent # calls to the same method. method = "#{name}" # Check for a valid method names, i.e. "set_xxx_yyy". method =~ /set_(\w+)/ or raise "Unknown method: #{method}\n" # Match the attribute, i.e. "@xxx_yyy". attribute = "@#{$1}" # Check that the attribute exists # ........ if method =~ /set\w+color$/ # for "set_property_color" methods value = get_color(args[0]) else # for "set_xxx" methods value = args[0].nil? ? 1 : args[0] end if value.respond_to?(:to_str) || !value.respond_to?(:+) s = %Q!#{attribute} = "#{value.to_s}"! else s = %Q!#{attribute} = #{value.to_s}! end eval s end |