Active Support Core Extension (3)

19
Active Support Core Extensions (3) ROR lab. DD-1 - The 3rd round - April 13, 2013 Hyoseong Choi

description

 

Transcript of Active Support Core Extension (3)

Page 1: Active Support Core Extension (3)

Active SupportCore Extensions (3)

ROR lab. DD-1- The 3rd round -

April 13, 2013

Hyoseong Choi

Page 3: Active Support Core Extension (3)

Ext. to Class• class_inheritable_accessor, _reader, _writer

active_support/core_ext/class/inheritable_attributes.rb

module ActionController  class Base    # FIXME: REVISE/SIMPLIFY THIS COMMENT.    # The value of allow_forgery_protection is inherited,    # but its value in a particular class does not affect    # the value in the rest of the controllers hierarchy.    class_inheritable_accessor :allow_forgery_protection  endend

: deprecated ➜ class_attribute instead

accessors for class-level data which is inherited but not shared with children

Page 9: Active Support Core Extension (3)

Ext. to String• truncate

active_support/core_ext/string/filters.rb

"Oh dear! Oh dear! I shall be late!".truncate(20)# => "Oh dear! Oh dear!..."

"Oh dear! Oh dear! I shall be late!".truncate(20, :omission => '…')# => "Oh dear! Oh …" …

"Oh dear! Oh dear! I shall be late!".truncate(18)# => "Oh dear! Oh dea...""Oh dear! Oh dear! I shall be late!".truncate(18, :separator => ' ')# => "Oh dear! Oh..."

Page 19: Active Support Core Extension (3)

ROR Lab.

감사합니다.����������� ������������������