Sha256: ba936c0e979127d8ebf8de3210946ca9b24392743ea78eeac048eaa7770da474

Contents?: true

Size: 1.5 KB

Versions: 12

Compression:

Stored size: 1.5 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

# Allow Wx-global functions to be accessed with nice syntax
module Wx
  extend WxRubyStyleAccessors
end

# Apply the syntax extensions to every class, both class methods and
# instance methods
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

12 entries across 12 versions & 2 rubygems

Version Path
wxruby-1.9.10-universal-darwin-9 lib/wx/accessors.rb
wxruby-1.9.10-x86-linux lib/wx/accessors.rb
wxruby-1.9.10-x86-mswin32-60 lib/wx/accessors.rb
wxruby-1.9.10-x86-mingw32 lib/wx/accessors.rb
wxruby-1.9.10-x86_64-linux lib/wx/accessors.rb
wxruby-1.9.9-universal-darwin-9 lib/wx/accessors.rb
wxruby-1.9.9-x86-mingw32 lib/wx/accessors.rb
wxruby-1.9.9-x86-linux lib/wx/accessors.rb
wxruby-1.9.9-x86-mswin32-60 lib/wx/accessors.rb
wxruby-ruby19-1.9.10-x86-darwin-9 lib/wx/accessors.rb
wxruby-ruby19-1.9.10-x86-linux lib/wx/accessors.rb
wxruby-ruby19-1.9.10-x86-mingw32 lib/wx/accessors.rb