9.3. Delegates With Prefixes
還有一堆玩具
#
past?, today? and future? for Date and Time classes to facilitate date/time comparisons.
#
Array#second through Array#tenth as aliases for Array#[1] through Array#[9]
#
Enumerable#many? to encapsulate collection.size > 1
#
Inflector#parameterize produces a URL-ready version of its input, for use in to_param.
#
Time#advance recognizes fractional days and weeks, so you can do 1.7.weeks.ago, 1.5.hours.since, and so on.
10.1. config.gems
To avoid deployment issues and make Rails applications more self-contained, it's possible to place copies of all of the gems that your Rails application requires in /vendor/gems
*
config.gem gem_name in your config/environment.rb file
*
rake gems to list all configured gems, as well as whether they (and their dependencies) are installed or frozen
*
rake gems:install to install missing gems to the computer
*
rake gems:unpack to place a copy of the required gems into /vendor/gems
*
rake gems:unpack:dependencies to get copies of the required gems and their dependencies into /vendor/gems
*
rake gems:build to build any missing native extensions
*
rake gems:refresh_specs to bring vendored gems created with Rails 2.1 into alignment with the Rails 2.2 way of storing them
You can unpack or install a single gem by specifying GEM=gem_name
2008年12月18日 星期四
rails 2.2 extra, delegate,gem
9.3. Delegates With Prefixes
還有一堆玩具
#
past?, today? and future? for Date and Time classes to facilitate date/time comparisons.
#
Array#second through Array#tenth as aliases for Array#[1] through Array#[9]
#
Enumerable#many? to encapsulate collection.size > 1
#
Inflector#parameterize produces a URL-ready version of its input, for use in to_param.
#
Time#advance recognizes fractional days and weeks, so you can do 1.7.weeks.ago, 1.5.hours.since, and so on.
10.1. config.gems
To avoid deployment issues and make Rails applications more self-contained, it's possible to place copies of all of the gems that your Rails application requires in /vendor/gems
*
config.gem gem_name in your config/environment.rb file
*
rake gems to list all configured gems, as well as whether they (and their dependencies) are installed or frozen
*
rake gems:install to install missing gems to the computer
*
rake gems:unpack to place a copy of the required gems into /vendor/gems
*
rake gems:unpack:dependencies to get copies of the required gems and their dependencies into /vendor/gems
*
rake gems:build to build any missing native extensions
*
rake gems:refresh_specs to bring vendored gems created with Rails 2.1 into alignment with the Rails 2.2 way of storing them
You can unpack or install a single gem by specifying GEM=gem_name
還有一堆玩具
#
past?, today? and future? for Date and Time classes to facilitate date/time comparisons.
#
Array#second through Array#tenth as aliases for Array#[1] through Array#[9]
#
Enumerable#many? to encapsulate collection.size > 1
#
Inflector#parameterize produces a URL-ready version of its input, for use in to_param.
#
Time#advance recognizes fractional days and weeks, so you can do 1.7.weeks.ago, 1.5.hours.since, and so on.
10.1. config.gems
To avoid deployment issues and make Rails applications more self-contained, it's possible to place copies of all of the gems that your Rails application requires in /vendor/gems
*
config.gem gem_name in your config/environment.rb file
*
rake gems to list all configured gems, as well as whether they (and their dependencies) are installed or frozen
*
rake gems:install to install missing gems to the computer
*
rake gems:unpack to place a copy of the required gems into /vendor/gems
*
rake gems:unpack:dependencies to get copies of the required gems and their dependencies into /vendor/gems
*
rake gems:build to build any missing native extensions
*
rake gems:refresh_specs to bring vendored gems created with Rails 2.1 into alignment with the Rails 2.2 way of storing them
You can unpack or install a single gem by specifying GEM=gem_name
2008年10月28日 星期二
instance_variable_get,delegate
http://ihower.idv.tw/blog/archives/1719
http://blog.gugl.org/archives/41
http://www.ruby-doc.org/core/classes/Object.html#M000380
http://www.ruby-doc.org/core/classes/Module.html#M001677
http://www.ruby-doc.org/core/classes/Hash.html#M002868
KEYS_MAPPINGS.each do |key, value|
define_method key, lambda { <= 用來生 method 的 method
instance_variable_get('@hash')[value] <= 可以直接拿 @hash instance variable 的 值
}
end
KEYS_MAPPINGS = {
:ask => 'BSELL' , :bid => 'BBUY' ,
:change => 'CHANGE', :high => 'HIGH',
:target_id => 'STKID' , :target_name => 'STKNAME'
}
delegate_opts = MarketData::KEYS_MAPPINGS.keys.reject do |e|
e == :target_id || e== :target_name
end.push(:to => :market_data) <= 呼叫 名為 market_data的 instance _function, 一般常是 has_one :thing 的 thing, 不過一樣意思, 就是叫後面這個 function
delegate *delegate_opts <= delegate_opts = [:ask, :bid, :change, :high, {:to => :market_data}]
<= delegate *delegate_opts 就是 delegate :ask, :bid, :change, :high, :to => :market_data
<= delegate 可以一次傳入多個 parameter
def market_data(key=nil)
@market_data ||= MarketData.target(target_id)
key && @market_data ? @market_data[key] : @market_data <= 有傳 key 跟沒傳key return的東西不同
end
[User model]
has_one :profile
field = Profile.content_columns.inject([]) do |result, column| <= content_columns, 濾掉 _id, _count的那些
result << column.name
end.push(:to => :profile)
delegate *field
User.first.address <= 現在可以直接這樣用了
訂閱:
文章 (Atom)