Sha256: 60797c695b0d4a9b2fc6049ca951df204da65d7510d818776bd4b4eea49e4117

Contents?: true

Size: 1014 Bytes

Versions: 3

Compression:

Stored size: 1014 Bytes

Contents

class Class
  # the define_constructor_class_method: method defines a constructor
  # class method.
  # e.g. for an instance method named "initialize:foo:" we'll define a class
  # method named "new:foo:" which creates a new instance of the class
  # (via allocate) & call the "initialize:foo:" method on it, before
  # returning the new instance.
  # NOTE:
  # the method_name argument to "define_constructor_class_method:"
  # contains only the rest of the method name, not including the
  # "initialize:" or "new:", so we'll have to prepend it ourselves
  define_method("define_constructor_class_method:") do |method_name|
    self.metaclass.send(:define_method, "new:" + method_name) do |*args|
      obj = self.allocate
      obj.__send__("initialize:" + method_name, *args)
      return obj
    end
  end

  define_method(":define_forward_method_missing") do
    define_method("method_missing") do |method_name, *args|
      self.__send__("unknown_message:with_params:", method_name, args)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fancy-0.10.0 boot/fancy_ext/class.rb
fancy-0.9.0 boot/fancy_ext/class.rb
fancy-0.8.0 boot/fancy_ext/class.rb