l'essentiel est invisible pour les yeux

Saturday, January 20, 2007

[rails] activesupport-1.4.0 CHANGELOG

Rails 1.2では、activesupport-1.4.0にアップデートしています。
activesupport-1.4.0/CHANGELOG


* Add ActiveSupport::Multibyte. Provides String#chars which lets you deal with strings as a sequence of chars, not of bytes. Closes #6242 [Julian Tarkhanov, Manfred Stienstra, Thijs van der Vossen & Jan Behrens]

ActiveSupport::Multibyteをrequireすると、String#charsメソッドが追加されます。charsメソッドはマルチバイト文字列への操作のプロキシ的な役割を果たします。

ActiveSupport::Multibyte

% ./script/console
Loading development environment.
>> "É À È Ù Â Ê Î".reverse
=> "\216� \212� \202� \231� \210� \200� \211\303"
>> "É À È Ù Â Ê Î".chars.reverse
=> #<activesupport::multibyte::chars:0xb700136c string="Î Ê Â Ù È À É">
>> "É À È Ù Â Ê Î".chars.reverse.string
=> "Î Ê Â Ù È À É"
>> "É À È Ù Â Ê Î".slice 1..2
=> "\211 "
>> "É À È Ù Â Ê Î".chars.slice 1..2
=> #<activesupport::multibyte::chars:0xb6ffaaf8 string=" À">
>> "É À È Ù Â Ê Î".chars.slice(1..2).string
=> " À"
>>



ActiveSupport::CoreExtensions::String::AccessがString#charsに対しての操作に変更されたため、マルチバイト文字を扱えるようになりました。

>> "É À È Ù Â Ê Î".at 0
=> "É"
>> "É À È Ù Â Ê Î".from 1
=> " À È Ù Â Ê Î"
>> "É À È Ù Â Ê Î".from 10
=> "Ê Î"
>> "É À È Ù Â Ê Î".first
=> "É"
>> "É À È Ù Â Ê Î".last
=> "Î"
>>


* Hash#to_xml supports Bignum and BigDecimal. #6313 [edibiase]

Hash#to_xmlがBignumとBigDecimal型に対応しました。

before

% ./script/console
>> {:te => 1111111111}.to_xml
=> "\n\n 1111111111\n\n"
>> {:te => BigDecimal.new("0.123456789123456789")}.to_xml
=> "\n\n 0.123456789123456789\n\n"
>>


activesupport-1.4.0

% ./script/console
>> {:te => 1111111111}.to_xml
=> "\n\n 1111111111\n\n"
>> {:te => BigDecimal.new("0.123456789123456789")}.to_xml
=> "\n\n 0.123456789123456789\n\n"
>>



* Hash.create_from_xml has been renamed to Hash.from_xml, alias will exist until Rails 2.0 [DHH]

Rails 2.0まではXML文字列からRubyの型を返すcreate_from_xmlが残されますが、WARNINGが発生します。Hash.from_xmlを使用しましょう。


>> Hash.create_from_xml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n <name>David</name>\n</hash>\n")
=> {"hash"=>{"name"=>"David"}}
>>

% tail -f log/development.log
DEPRECATION WARNING: Hash.create_from_xml has been renamed to Hash.from_xml See http://www.rubyonrails.org/deprecation for details. (called from irb_binding at (irb):24)



* alias_method_chain works with accessor= methods also. #6153 [Caio Chassot]

* Added Module#alias_attribute [Jamis/DHH]. Example:

class Content < e =" Email.find(1)"> "Superstars"
e.subject # => "Superstars"
e.subject? # => true
e.subject = "Megastars"
e.title # => "Megastars"


alias_methodが属性の代入に対しても使用できるように変更。(破壊メソッドを表す!と真偽値を返す?だけがサポートされていました)。また、alias_methodと同じように、プロパティのエイリアスを設定できるalias_attributeが追加されました。


* Optional identity for Enumerable#sum defaults to zero. #5657 [gensym@mac.com]

Enumerable#sumでブロックを評価した値の合計値が計算できます。
inject(0) {|sum, p| sum + yield(p)}と等価です。


>> [100,200,300].sum {|yen| yen * 1.05}
=> 630.0


* Enhance Symbol#to_proc so it works with list objects, such as multi-dimensional arrays. Closes #5295

Symbol#to_procがネストした配列に対しても適用できるようになりました。


>> [[1, "one"], [2, "two"], [3, "three"]].map(&:last)
=> ["one", "two", "three"]

ActiveSupport::OrderedHash#valuesの追加。このクラスは、キーの値をソートした状態で配列として保持します。ハッシュと同様にキーでアクセスできます。


% ./script/console
>> oh = ActiveSupport::OrderedHash.new
>> oh[:a] = 2; oh[:b] = 1; oh[:c] = 3;
>> oh.keys
=> [:a, :b, :c]
>> oh.values
=> [2, 1, 3]
>> oh
=> [[:a, 2], [:b, 1], [:c, 3]]



* Added Array#to_s(:db) that'll produce a comma-separated list of ids

Array#to_s(:db)の追加。Array.map(&:id).join(',')と等価。