lib/dynamic_slot_object.fy in fancy-0.6.0 vs lib/dynamic_slot_object.fy in fancy-0.7.0
- old
+ new
@@ -1,22 +1,45 @@
-class DynamicSlotObject : BasicObject {
+class DynamicSlotObject : Fancy BasicObject {
+ """
+ Helper class to dynamically create @Object@s with slots defined by sending messages to it.
+
+ Example:
+ dso = DynamicSlotObject new
+ dso name: \"Chris\"
+ dso age: 25
+ dso country: \"Germany\"
+ dso object # => Object with slots 'name, 'age and 'country defined
+ """
+
def initialize {
@object = Object new
}
def object {
+ @object metaclass read_write_slots: (@object slots)
@object
}
def unknown_message: m with_params: p {
m to_s split: ":" . each_with_index: |slotname idx| {
@object set_slot: slotname value: $ p[idx]
}
}
}
-class DynamicKeyHash : BasicObject {
+class DynamicKeyHash : Fancy BasicObject {
+ """
+ Helper class to dynamically create @Hash@es with keys and values defined by sending messages to it.
+
+ Example:
+ dkh = DynamicKeyHash new
+ dkh name: \"Chris\"
+ dkh age: 25
+ dkh country: \"Germany\"
+ dkh hash # => <['name => \"Chris\", 'age => 25, 'country => \"Germany\"]>
+ """
+
def initialize: @deep (false) {
@hash = <[]>
}
def hash {
@@ -34,10 +57,23 @@
@hash[slotname to_sym]: val
}
}
}
-class DynamicValueArray : BasicObject {
+class DynamicValueArray : Fancy BasicObject {
+ """
+ Helper class to dynamically create @Array@s with values defined by sending messages to it.
+
+ Example:
+ dva = DynamicValueArray new
+ dva name: \"Chris\"
+ dva age: 25
+ dva country: \"Germany\"
+ dva something_else
+
+ dva array # => [['name, \"Chris\"], ['age, 25], ['country, \"Germany\"], 'something_else]
+ """
+
def initialize {
@arr = []
}
def array {