More Related Content
Similar to Activesupport - Leckerbissen (Kurzvortrag)
Similar to Activesupport - Leckerbissen (Kurzvortrag) (20)
Activesupport - Leckerbissen (Kurzvortrag)
- 2. Utility classes and standard library
extensions from Rails
require ‘active_support/all’
require ‘active_support/core_ext/string’
- 3. Klassiker
variable.blank? #=> true
variable.present? #=> false
[0,1,2,3].first #=> 0
[0,1,2,3].second #=> 1
2.months.ago #=> 2012-04-15 19:30:00 +0200
- 4. unshift => prepend
a = [1,2,3,4]
a.prepend(0) #=> [0,1,2,3,4]
a.prepend(-1,0) #=> [-1,0,1,2,3,4]
- 5. in_groups_of
%w(1 2 3 4 5 6 7).in_groups_of(3) {|group| p group}
["1", "2", "3"]
["4", "5", "6"]
["7", nil, nil]
- 6. module Config
mattr_accessor :url
end
class PlaceholderImage
cattr_accessor :base_path
end
Config.url = “http://www.freebsd.org”
PlaceholderImage.base_path = “/images”
=> ActiveSupport::Configurable
- 7. Rails 4 Beta
NumberHelpers von ActionView nach ActiveSupport
verschoben
1234567.to_s(:human_size) #=> "1.18 MB"
302.243989234.to_s(:percentage, :precision => 5) #=> 302.24399%
Editor's Notes
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n