lib/rbx/object.fy in fancy-0.3.3 vs lib/rbx/object.fy in fancy-0.4.0

- old
+ new

@@ -1,81 +1,149 @@ -class Class { - def alias_method: new for: old { - alias_method(new, old) - } - - def ruby_alias: method_name { - alias_method(":" + (method_name to_s), method_name) - } -} - -class String { - alias_method: ":+" for: "+" -} - class Object { - ruby_alias: '== ruby_alias: '=== ruby_alias: 'class ruby_alias: 'inspect + ruby_alias: 'object_id + ruby_alias: 'instance_variables def initialize { initialize() } + def require: file_path { + """ + Loads and evaluates a given Fancy source file by trying to find the specified + @file_path in Fancy's loadpath (see @Fancy::CodeLoader@). + Relative paths are allowed (and by default expected). + """ + Fancy CodeLoader require: file_path + } + def dclone { "Returns a deep clone of self using Ruby's Marshal class." Marshal load(Marshal dump(self)) } def to_s { + """ + @return @String@ represenation of @self. + """ + to_s() } def set_slot: slotname value: val { + """ + @slotname Name of slot to be set. + @val Value for slot to be set. + + Sets an object's slot with a given value. + """ + instance_variable_set("@" ++ slotname, val) } def get_slot: slotname { + """ + @slotname Name of slot to get the value of. + @return Value of slot with name @slotname. + + Returns the value of a slot of @self. + """ + instance_variable_get("@" ++ slotname) } def define_singleton_method: name with: block { + """ + @name Name of the method to be defined on @self. + @block @Block@ to be used as the method's body. + + Dynamically defines a method on @self's metaclass (a singleton method) using a given @Block@. + """ + metaclass define_method: name with: block } def undefine_singleton_method: name { + """ + @name Name of the method to be undefined no @self's metaclass. + + Undefines a singleton method of @self. + """ + metaclass undefine_method: name } def is_a?: class { - "Indicates, if an object is an instance of a given Class." + """ + @class @Class@ to check for if @self is an instance of. + @return @true if @self is an instance of @class, @false otherwise. + + Indicates, if an object is an instance of a given Class. + """ + is_a?(class) } def kind_of?: class { - "Indicates, if an object is an instance of a given Class." + """ + Same as Object#is_a?: + Indicates, if an object is an instance of a given Class. + """ + kind_of?(class) } - def send_message: message { + def receive_message: message { + """ + @message Name of message to be sent to @self dynamically. + + Dynamically sends a given message (without parameters) to @self. + """ + send(message_name: message) } - def send_message: message with_params: params { - ruby: (message_name: message) args: params + def receive_message: message with_params: params { + """ + @message Name of message to be sent to @self dynamically. + @params @Array@ of parameters used with @message. + + Dynamically sends a given message with parameters to @self. + """ + + ruby: (message_name: message) args: params } def message_name: symbol { symbol = symbol to_s - if: (symbol =~ /:/) then: { - symbol - } else: { - ":" ++ symbol + match symbol =~ /:/ { + case nil -> + ":" ++ symbol + case _ -> + symbol } } def responds_to?: message { + """ + @message The message to check for (preferably a Symbol). + @return @true if @self responds to @message, @false otherwise. + + Indicates if an object responds to a given message. + """ + respond_to?(message_name: message) + } + + def extend: class { + """ + @class @Class@ to extend @self with. + + Extends @self with the methods in @class (by including its methods in @self's metaclass). + """ + + metaclass include: class } }