Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

CHANGE: Moved initialize logic to Storable.from_array.

  • Loading branch information...
commit ae83c924c2f305da237354218e2831b33d0d220e 1 parent fe47022
@delano authored
Showing with 16 additions and 5 deletions.
  1. +7 −0 CHANGES.txt
  2. +9 −5 lib/storable.rb
View
7 CHANGES.txt
@@ -3,6 +3,13 @@ STORABLE, CHANGES
* TODO: Handle nested hashes and arrays.
* TODO: to_xml, see: http://codeforpeople.com/lib/ruby/xx/xx-2.0.0/README
+#### 0.8.4 (2010-12-23) #############################
+
+* CHANGE: Moved initialize logic to Storable.from_array.
+
+ NOTE: Classes that rely on this logic when creating
+ new instances will need to call from_array instead!
+
#### 0.8.3 (2010-11-02) #############################
View
14 lib/storable.rb
@@ -128,11 +128,7 @@ def has_field?(n)
# +args+ is a list of values to set amongst the fields.
# It's assumed that the order values matches the order
def initialize(*args)
- (self.class.field_names || []).each_with_index do |n,index|
- break if (index+1) > args.size
- self.send("#{n}=", args[index])
- end
- preprocess if respond_to?(:preprocess)
+ preprocess if respond_to? :preprocess
end
# See SUPPORTED_FORMATS for available values
@@ -207,6 +203,14 @@ def self.from_hash(from={})
end
end
+ def self.from_array(from=[])
+ return nil if !from || from.empty?
+ (self.class.field_names || []).each_with_index do |n,index|
+ break if index >= from.size
+ self.send("#{n}=", from[index])
+ end
+ end
+
def call(fname)
unless field_types[fname.to_sym] == Proc &&
Proc === self.send(fname)
Please sign in to comment.
Something went wrong with that request. Please try again.