Module: Iup::AttributeBuilders
- Included in:
- DragDropAttributes, ScrollBarAttributes, Timer, Widget
- Defined in:
- lib/wrapped/attribute-builders.rb
Overview
methods to help construct attribute methods
Instance Method Summary collapse
-
#define_attribute(name) ⇒ Object
Given the name of an attribute, this method creates reader and writer methods.
-
#define_id_attribute(name) ⇒ Object
Given the name of an attribute, this method creates a new method requiring an id number as a parameter and an optional value.
-
#define_id_reader(name) ⇒ Object
Creates a reader method for an indexed attribute.
-
#define_id_writer(name) ⇒ Object
Creates a writer method for an indexed attribute.
-
#define_property_attribute(name) ⇒ Object
Creates reader/writer method for a property attribute.
-
#define_property_reader(name) ⇒ Object
Creates a reader method for a property attribute.
-
#define_property_writer(name) ⇒ Object
Creates a writer method for a property attribute.
-
#define_reader(name) ⇒ Object
Creates a reader method for attribute of given name.
-
#define_writer(name) ⇒ Object
Creates a writer method for attribute of given name.
Instance Method Details
#define_attribute(name) ⇒ Object
Given the name of an attribute, this method creates reader and writer methods.
9 10 11 12 |
# File 'lib/wrapped/attribute-builders.rb', line 9 def define_attribute name define_reader name define_writer name end |
#define_id_attribute(name) ⇒ Object
Given the name of an attribute, this method creates a new method requiring an id number as a parameter and an optional value. Providing the value will set the named attribute for this object using the id number, e.g. “ITEM1”, or else the current value will be returned. This supports attributes such as “ITEM1” “ITEM2” by making the id number a parameter.
35 36 37 38 39 40 41 42 43 |
# File 'lib/wrapped/attribute-builders.rb', line 35 def define_id_attribute name define_method "#{name}" do |id, val=nil| if val.nil? IupLib.IupGetAttribute(@handle, "#{name}#{id}".upcase).first else IupLib.IupSetAttribute(@handle, "#{name}#{id}".upcase, val.to_s) end end end |
#define_id_reader(name) ⇒ Object
Creates a reader method for an indexed attribute. Note: index starts from 1, as in IUP. This supports attributes such as “ITEM1” “ITEM2” by making the id number a parameter.
48 49 50 51 52 |
# File 'lib/wrapped/attribute-builders.rb', line 48 def define_id_reader name define_method "#{name}" do |id| IupLib.IupGetAttribute(@handle, "#{name}#{id}".upcase).first end end |
#define_id_writer(name) ⇒ Object
Creates a writer method for an indexed attribute. Note: index starts from 1, as in IUP. This supports attributes such as “ITEM1” “ITEM2” by making the id number a parameter.
57 58 59 60 61 |
# File 'lib/wrapped/attribute-builders.rb', line 57 def define_id_writer name define_method "#{name}" do |id, val| IupLib.IupSetAttribute(@handle, "#{name}#{id}".upcase, val.to_s) end end |
#define_property_attribute(name) ⇒ Object
Creates reader/writer method for a property attribute.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/wrapped/attribute-builders.rb', line 64 def define_property_attribute name attribute = name.to_s.upcase define_method "#{name}" do |property, val=nil| if val.nil? IupLib.IupSetAttribute(@handle, attribute, property.upcase).first else IupLib.IupSetAttribute(@handle, attribute, "#{property}=#{val}".upcase) end end end |
#define_property_reader(name) ⇒ Object
Creates a reader method for a property attribute. This supports attributes such as “ITEM=val”, providing a parameter for the property name.
77 78 79 80 81 82 |
# File 'lib/wrapped/attribute-builders.rb', line 77 def define_property_reader name attribute = name.to_s.upcase define_method "#{name}" do |property| IupLib.IupGetAttribute(@handle, attribute, property.upcase).first end end |
#define_property_writer(name) ⇒ Object
Creates a writer method for a property attribute. This supports attributes such as “ITEM=val”, providing a parameter for the property name.
86 87 88 89 90 91 |
# File 'lib/wrapped/attribute-builders.rb', line 86 def define_property_writer name attribute = name.to_s.upcase define_method "#{name}" do |property, val| IupLib.IupSetAttribute(@handle, attribute, "#{property}=#{val}".upcase) end end |
#define_reader(name) ⇒ Object
Creates a reader method for attribute of given name.
15 16 17 18 19 20 |
# File 'lib/wrapped/attribute-builders.rb', line 15 def define_reader name attribute = name.to_s.upcase define_method name do IupLib.IupGetAttribute(@handle, attribute).first end end |
#define_writer(name) ⇒ Object
Creates a writer method for attribute of given name.
23 24 25 26 27 28 |
# File 'lib/wrapped/attribute-builders.rb', line 23 def define_writer name attribute = name.to_s.upcase define_method "#{name}=" do |val| IupLib.IupSetAttribute(@handle, attribute, val.to_s) end end |