Sha256: e05570ef2b06099d6c993a74447cc082e4c6cfaad56ed6133c7ec759d131aba6
Contents?: true
Size: 1007 Bytes
Versions: 7
Compression:
Stored size: 1007 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
7 entries across 7 versions & 1 rubygems