Sha256: eda0dcb48d1469f3a524cc4fdbb22617bc903bd42cb2d9fff4d68102abbbe94d

Contents?: true

Size: 1.31 KB

Versions: 34

Compression:

Stored size: 1.31 KB

Contents

# = WxSugar - Accessors
#
# The default WxRuby interface has lots and lots of methods like
#
#  * get_position()
#  * set_size(a_size)
#  * is_checked()
# 
# and so on. Methods that retrieve set, or query attributes of an object
# are more normally in Ruby called simply by the attribute name:
#
#  * position()
#  * size = a_size
#  * checked?
#
# This extension creates an alias for every WxRuby instance method that
# begins with +get_+, +set_+ or +is_+. Note that if you are calling a
# 'setter' method on self, you must explicitly send the message to self:
# 
#  # set's self size to be 100px by 100px
#  self.size = Wx::Size.new(100, 100)
#  # only sets the value of a local variable 'size'
#  size = Wx::Size.new

module WxRubyStyleAccessors
  def method_missing(sym, *args)
    case sym.to_s
    when /^(.*)\=$/
      meth = "set_#{$1}"
    when /^(.*)\?$/
      meth = "is_#{$1}"
    else
      meth = "get_#{sym}"
    end
    if respond_to?(meth)
      send(meth, *args)
    else
      e = NoMethodError.new("undefined method '#{sym}' for #{self.inspect}")
      e.set_backtrace(caller)
      Kernel.raise e
    end
  end
end

all_classes = Wx::constants.collect { | c | Wx::const_get(c) }.grep(Class)

all_classes.each do | klass |
  klass.class_eval do
    include WxRubyStyleAccessors
    extend WxRubyStyleAccessors
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
wxruby-1.9.7-i386-mswin32 lib/wx/accessors.rb
wxruby-1.9.5-i386-mswin32 lib/wx/accessors.rb
wxruby-1.9.4-i386-mswin32 lib/wx/accessors.rb
wxruby-1.9.3-i386-mswin32 lib/wx/accessors.rb
wxruby-1.9.2-powerpc-darwin8.10.0 lib/wx/accessors.rb
wxruby-1.9.2-i686-linux lib/wx/accessors.rb
wxruby-1.9.2-i686-darwin8.8.2 lib/wx/accessors.rb
wxruby-1.9.2-i386-mswin32 lib/wx/accessors.rb
wxruby-1.9.1-powerpc-darwin8.3.0 lib/wx/accessors.rb
wxruby-1.9.1-i686-linux lib/wx/accessors.rb
wxruby-1.9.1-i686-darwin8.4.1 lib/wx/accessors.rb
wxruby-1.9.1-i386-mswin32 lib/wx/accessors.rb
wxruby-1.9.1-x86_64-linux lib/wx/accessors.rb
wxruby-1.9.2-x86_64-linux lib/wx/accessors.rb
wxruby-1.9.3-universal-darwin lib/wx/accessors.rb
wxruby-1.9.3-x86-linux lib/wx/accessors.rb
wxruby-1.9.4-x86-linux lib/wx/accessors.rb
wxruby-1.9.4-x86_64-linux lib/wx/accessors.rb
wxruby-1.9.5-universal-darwin-9 lib/wx/accessors.rb
wxruby-1.9.5-x86-linux lib/wx/accessors.rb