Rails 1.0 -> 1.1 ã® ActiveSupport å¤æ´ç¹ã¾ã¨ã
Ruby on Rails 1.0 ã¾ã§ã¯ AWDwR æ¬ãèªãã§ä½¿ãæ¹ã解ã£ã¦ã人ãå¤ãã¨æãã®ã§ããã1.1 以éã§ã©ããªè©³ç´°ãªæ©è½ãå ãã£ãã®ãã¯ãã¾ãç¥ããã¦ã¾ããã
ãã®ããã« ActiveSupport ã® CHANGELOG ãæ·¡ã
ã¨èªãã§ã¾ã¨ãã¦ã¿ã¾ãããééã£ã¦ãå¯è½æ§ãããã®ã§ããããç®æããã£ãããææä¸ããã
Add CachingTools::HashCaching to simplify the creation of nested, autofilling hashes. [Nicholas Seckar]
CachingTools::HashCaching ã¨ãã Hash ãå©ç¨ããã·ã³ãã«ãªãã£ãã·ã¥æ©è½ã®ã¢ã¸ã¥ã¼ã«ãå ããã¾ããããã®ã¢ã¸ã¥ã¼ã«ãå©ç¨ãããã¯ã©ã¹ã§ extend ãã¦
hash_cache :methodname
ã¨ããã¨ããã®ã¡ã½ãããå¼ã³åºãããæã«çµæãèªå㧠methodname + cache *1ã¨ãã Hash ã®ã¤ã³ã¹ã¿ã³ã¹å¤æ°_ã«æ ¼ç´ããã¾ãããã®ããä¸åº¦
obj.methodname('foo', 'bar')
ã¨ã¡ã½ãããå¼ã³åºããå ´åã
obj.methodname_cache['foo']['bar']
ã«èªåã§çµæãæ ¼ç´ããã¦ãã¾ãã
Added option to String#camelize to generate lower-cased camel case by passing in :lower, like "super_man".camelidze(:lower) # => "superMan" [DHH]
å é 㯠cemel åããã« ãã以éã camel åããããã®å¼æ° :lower ã追å ããã¾ããããã¶ã RJS Templateå é¨ã§ãã使ãããã«è¿½å ãªã®ã§ãããã
>> 'foo_bar'.camelize(:lower) => "fooBar"
Added Hash#diff to show the difference between two hashes [Chris McGrath]
hash ã®æ§é ã®å·®ç°ã hash ã§è¿ãã¦ããã¾ãã
>> {:a => 'b', :c => 'd'}.diff({:a => 'b', :c => 'e'}) => {:c=>"d"}
Enhance Inflector.underscore to convert '-' into '_' (as the inverse of Inflector.dasherize) [Jamis Buck]
- ã _ ã« å¤æãã¾ãã
>> 'foo-bar'.underscore => "foo_bar"
Added Hash#to_xml and Array#to_xml that makes it much easier to produce XML from basic structures [DHH].
Hash ã XML ã¨ãã¦åºåãã¦ããã¾ããå é¨ã®åãè¦ç´ ã¨ãã¦ããã£ã½ãåºåãã¦ãããããã§ãã
>> puts({ :name => "David", :street_name => "Paulina", :age => 26, :moved_on => Date.new(2005, 11, 15) }.to_xml) <?xml version="1.0" encoding="UTF-8"?> <hash> <street-name>Paulina</street-name> <age type="integer">26</age> <name>David</name> <moved-on type="date">2005-11-15</moved-on> </hash>
ã¾ãå¼æ°ã«ãªãã·ã§ã³ã¨ãã¦ããããæå®ã§ãã¾ãã
http://api.rails2u.com/docs/activerecord/classes/ActiveRecord/Base.html#M000449
Add Enumerable#group_by for grouping collections based on the result of some block. Useful, for example, for grouping records by date.
å¼æ°ã«æ¸¡ãã block ã®çµæã§ã³ã¬ã¯ã·ã§ã³ãã¦ããã¾ãããµã³ãã«ã§ã¯ ActiveRecord ãªãã¸ã§ã¯ãã® day ãã£ã¼ã«ãã®å¤ã§ã³ã¬ã¯ã·ã§ã³ãã¦ã¾ãã
latest_transcripts.group_by(&:day).each do |day, transcripts| p "#{day} -> #{transcripts.map(&:class) * ', '}" end
次ã®ä¾ã§ã¯ :result ã true ã false ã§ã³ã¬ã¯ã·ã§ã³ãã¦ã¾ãã
>> ([ ?> { ?> :name => 'foo', ?> :result => true, ?> }, ?> { ?> :name => 'bar', ?> :result => false, ?> }, ?> { ?> :name => 'baz', ?> :result => false, ?> }, ?> { ?> :name => 'hoge', ?> :result => false, ?> }, ?> ]).group_by {|h| h[:result]} => {false=>[{:name=>"bar", :result=>false}, {:name=>"baz", :result=>false}, {:name=>"hoge", :result=>false}], true=>[{:name=>"foo", :result=>true}]}
Add Array#in_groups_of, for iterating over an array in groups of a certain size.
arrya ãå¼æ°ã®æ°å¤ãã¨ã«åºåã£ã¦ã°ã«ã¼ãåãã¦ããã¾ãããã¼ãã«ã¬ã¤ã¢ã¦ããªããã§ä¾¿å©ããã§ãã
>> %w(1 2 3 4 5 6 7).in_groups_of(3) {|g| p g} ["1", "2", "3"] ["4", "5", "6"] ["7", nil, nil]
ã¯ã¦ãªãã¼ãã«è¨æ³ãªãããä½ãããå ´åã¯ãããªæãã«ã
>> ('a'..'z').to_a.in_groups_of(5) {|g| puts g.unshift('').push('').join('|')} |a|b|c|d|e| |f|g|h|i|j| |k|l|m|n|o| |p|q|r|s|t| |u|v|w|x|y| |z|||||
Added Kernel#daemonize to turn the current process into a daemon that can be killed with a TERM signal [DHH]
Kernel#daemonize ãå¼ã³åºãã ãã§ç°¡æ daemonåãã§ãã¾ããããã¯ã°ã©ã¦ã³ãã¸ã§ãã¨ãã¦ä½¿ãã¦ã¼ãã£ãªãã£ãä½ãã¨ãã¨ãã«ä½¿ãããã§ããæ®é Daemons ã¨ãã¤ãããªãã¨ãæã£ããæããªãã£ããã
ã¾ã win32 ãªç°å¢ã§ã¯ãã¾ãåãã¾ããã
Added Time#beginning_of_quarter #3607 [cohen.jeff@gmail.com]
æå»ã®ååæé ãæ±ããã¡ã½ãã Time#beginning ã追å ããã¾ããã
>> Time.now => Mon May 22 15:01:50 JST 2006 >> Time.now.beginning_of_quarter => Sat Apr 01 00:00:00 JST 2006
Make String#last return the string instead of nil when it is shorter than the limit [Scott Barron].
æååã®æå¾ã®æåãæ±ãã last ã¡ã½ããã«é·ããæå®ã§ããããã«ãªãã¾ããã
>> 'foobar'.last => "r" >> 'foobar'.last 3 => "bar"
Add 'around' methods to Logger, to make it easy to log before and after messages for a given block as requested in #3809.
logger ã« around_* ã¡ã½ããã追å ããã第ä¸ç¬¬äºå¼æ°ã«before, after ã¨ãªããã°ã¡ãã»ã¼ã¸ãæå®ãããããã¯å é¨ã§ããããã§ããããã§ãã
>> logger = Logger.new STDOUT >> logger.around_info('---- ãããã ----', '---- ããã¾ã§ ----') { ?> logger.debug 'example' >> } ---- ãããã ---- example ---- ããã¾ã§ ----
Added delegation support to Module that allows multipledelegations at once (unlike Forwardable in the stdlib) [DHH].
ã¤ã³ã¹ã¿ã³ã¹å¤æ°(?)ã¾ã¨ãã¦ã¡ã½ãããããªã²ã¼ãããæ©è½ã Module ã«ãµãã¼ããããããã§ãã
class Account < ActiveRecord::Base has_one :subscription delegate :free?, :paying?, :to => :subscription delegate :overdue?, :to => "subscription.last_payment" end account.free? # => account.subscription.free? account.overdue? # => account.subscription.last_payment.overdue?
class ActiveRecord::Base delegate :columns, :column_names, :to=>âself.classâ end
Added reusable reloading support through the inclusion of the Relodable module that all subclasses of ActiveRecord::Base, ActiveRecord::Observer, ActiveController::Base, and ActionMailer::Base automatically gets. This means that these classes will be reloaded by the dispatcher when Dependencies.mechanism = :load. You can make your own models reloadable easily
development æã« include ãã¦ããã ãã§èªåã§ã¯ã©ã¹ãªã©ããªãã¼ããã¦ããã Reloadable ã¢ã¸ã¥ã¼ã«ã追å ããã¾ããã詳ãã㯠ã½( ã»âã»)ããã¾ãã¾ã¼(2006-03-07) ã§ã
Add Object#instance_exec, like instance_eval but passes its arguments to the block. (Active Support will not override the Ruby 1.9 implementation of this method.) [Sam Stephenson]
instance_eval ã® block ã«å¼æ°ãã¨ãããããªã¡ã½ãããObject#instance_exec ã追å ããã¾ããã
>> block = Proc.new { |value| [self, value] } => #<Proc:0x4087347c@(irb):44> >> 'hello'.instance_exec('goodbye', &block) => ["hello", "goodbye"]
Add Proc#bind(object) for changing a proc or block's self by returning a Method bound to the given object. Based on why the lucky stiff's "cloaker" method. [Sam Stephenson]
Proc#bind ã追å ããã¾ãããbind ãã object ã Proc ã® block ã®ä¸ã§ã¯ self ã¨ãã¦åç §ãããããã§ãã
>> example = Proc.new {|method| self.send(method) } => #<Proc:0x40877f90@(irb):59> >> example.bind('string').call(:length) => 6
Add ActiveSupport::JSON and Object#to_json for converting Ruby objects to JSON strings.
Object ã JSON å½¢å¼ã® String ã«å¤æãã Object#to_json ãå®è£ ããã¾ããã
>> puts({:foo => 'bar', :hoge => 'huga'}.to_json) {"hoge": "huga", "foo": "bar"}
Add Object#with_options for DRYing up multiple calls to methods having shared options. [Sam Stephenson]
ãªãã·ã§ã³ã¨ã㦠Hash ãå¼æ°ã§æ¸¡ããããªå ´åã«å ±æã§ãã with_options ã¡ã½ããã追å ããã¾ããã
ActionController::Routing::Routes.draw do |map| # Account routes map. do |account| account.home ,:controller => 'account', '', :action => 'dashboard' account.signup ,:controller => 'account', 'signup', :action => 'new' account.logout ,:controller => 'account', 'logout', :action => 'logout' end end
ã次ã®ããã«æ¸ããã¨ãã§ããããã«ãªãã¾ããã
ActionController::Routing::Routes.draw do |map| # Account routes map.with_options(:controller => 'account') do |account| account.home '', :action => 'dashboard' account.signup 'signup', :action => 'new' account.logout 'logout', :action => 'logout' end end
Add Symbol#to_proc, which allows for, e.g. [:foo, :bar].map(&:to_s). [Marcel Molina Jr.]
Symbol#to_proc ã追å ããã¾ãããç¥ã£ã¦ããã¨ããªã便å©ã§ããåè: ã½( ã»âã»)ããã¾ãã¾ã¼(2006-03-09)
Added the following methods [Marcel Molina Jr., Sam Stephenson]:
Object#copy_instance_variables_from(object) to copy instance variables from one object to another
å¥ã®ãªãã¸ã§ã¯ãããã¤ã³ã¹ã¿ã³ã¹å¤æ°ãã³ãã¼ãã¾ãã
Object#extended_by to get an instance's included/extended modules
ã¤ã³ã¹ã¿ã³ã¹ã include, extend ãã Module ä¸è¦§ãåå¾ãã¾ãã
>> 'string'.extended_by => [ActiveSupport::CoreExtensions::String::Iterators, ActiveSupport::CoreExtensions::String::StartsEndsWith, ActiveSupport::CoreExtensions::String::Inflections, ActiveSupport::CoreExtensions::String::Conversions, ActiveSupport::CoreExtensions::String::Access, Enumerable, Comparable]
Object#extend_with_included_modules_from(object) to extend an instance with the modules from another instance
å¥ã®ãªãã¸ã§ã¯ãããã¤ã³ã¹ã¿ã³ã¹ã¡ã½ãããã³ãã¼ãã¾ãã
*1:_cache ã¨ããååã¯å¤æ´å¯è½