lib/object.fy in fancy-0.8.0 vs lib/object.fy in fancy-0.9.0
- old
+ new
@@ -137,10 +137,23 @@
"""
[self]
}
+ @@__to_hash_exclude_slots__ = ['_fancy_documentation]
+ def to_hash {
+ """
+ @return @Hash@ representation of @self based on slot values.
+ """
+
+ h = <[]>
+ slots - @@__to_hash_exclude_slots__ each: |s| {
+ h[s]: $ get_slot: s
+ }
+ h
+ }
+
def to_i {
"""
@return @Fixnum@ representation of @self.
"""
@@ -238,13 +251,23 @@
"""
Same as:
cond_block while_do: body_block
"""
- cond_block while_do: body_block
+ cond_block while_true: body_block
}
+ def while: condition do: body else: alternative {
+ """
+ @condition @Block@ to be used as condition for while loop.
+ @body @Block@ to be called while @condition yields @true.
+ @alternative @Block@ to be called if @body never got called (@condition never yielded @true).
+ """
+
+ condition while_true: body else: alternative
+ }
+
def until: cond_block do: body_block {
"""
Same as:
cond_block until_do: body_block
"""
@@ -533,14 +556,17 @@
"""
@block @Block@ to be run only by one Thread at a time.
Runs a given @Block@ in a synchronized fashion if called by multiple Threads.
Uses a @Mutex@ in the background for synchronization (created on demand for each @Object@).
+ Calls @block with @self.
"""
@__mutex__ = @__mutex__ || { Mutex new() }
- @__mutex__ synchronize(&block)
+ @__mutex__ synchronize() {
+ block call: [self]
+ }
}
def copy_slots: slots from: object {
"""
@slots @Fancy::Enumerable@ of slot names to copy from @object.
@@ -690,22 +716,22 @@
}
"""
{ return value } unless: var_name
unless: block do: {
- Thread current[var_name]: value
+ Thread current set_dynamic_var: var_name to: value
return value
}
- oldval = Thread current[var_name]
+ oldval = Thread current dynamic_var: var_name
try {
- Thread current[var_name]: value
+ Thread current set_dynamic_var: var_name to: value
block call
return value
} finally {
try { ensure_block call } catch {}
- Thread current[var_name]: oldval
+ Thread current set_dynamic_var: var_name to: oldval
}
}
def with_output_to: filename do: block {
"""
@@ -770,10 +796,10 @@
"""
@exception_classes @Fancy::Enumerable@ of @Exception@s to ignore within @block.
@block @Block@ to be executed while ignoring (catching but not handling) @Exception@s defined in @exception_classes.
Example:
- ignoring: (IOError, ZeroDivisionError) in: {
+ ignoring: (IOError, ZeroDivisionError) do: {
# do something
}
"""
try {
\ No newline at end of file