Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/rbcurse/rwidget.rb

Instance Method Summary collapse

Instance Method Details

#dsl_accessor(*symbols) ⇒ Object

also creates a attr_writer so you can use =.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rbcurse/rwidget.rb', line 47

def dsl_accessor(*symbols)
  symbols.each { |sym|
    class_eval %{
      def #{sym}(*val)
        if val.empty?
          @#{sym}
        else
          @#{sym} = val.size == 1 ? val[0] : val
          @config["#{sym}"]=@#{sym}
        end
      end
  attr_writer sym
    }
  }
end

#dsl_property(*symbols) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rbcurse/rwidget.rb', line 62

def dsl_property(*symbols)
  symbols.each { |sym|
    class_eval %{
      def #{sym}(*val)
        if val.empty?
          @#{sym}
        else
          oldvalue = @#{sym}
          @#{sym} = val.size == 1 ? val[0] : val
          newvalue = @#{sym}
          @config["#{sym}"]=@#{sym}
          if oldvalue != newvalue
            fire_property_change("#{sym}", oldvalue, newvalue)
          end
        end
      end
  #attr_writer sym
      def #{sym}=val
         #{sym}(val)
      end
    }
  }
end