ActionSupport in Rails4 Part1
Recently i study documents in ruby edgeguides. There are a lot of methods in ActionSupport chapter. I record something useful here and for reference in the future.
Extensions to All Objects
Defined in active_support/core_ext/object/blank.rb.
blank?
Following vlaues are considered to be blank.
* nil and false
* strings composed only of whitespace (see note below)
* empty arrays and hashes
In particular, 0 and 0.0 are not blank.
present?
The method present?
is equivalent to !blank?
presence
Returns itself if present?, and nil otherwise. Useful
1
|
|
Defined in active_support/core_ext/object/duplicable.rb.
duplicable?
By definition all objects are duplicable? except nil, false, true, symbols, numbers, class, and module objects.
Defined in active_support/core_ext/object/duplicable.rb.
deep_dup
Deep duplicate. Normally, dup
an object that contains other objects, Ruby only creates a shallow copy of the object.
Defined in active_support/core_ext/object/try.rb.
try
Try to call a method only if it is not nil
1 2 3 4 5 6 7 |
|
try can also be called without arguments but a block
1
|
|
Defined in active_support/core_ext/object/with_options.rb.
with_options
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Defined in active_support/core_ext/object/instance_variables.rb.
instance_values
1 2 3 4 5 6 7 |
|
instance_variable_names
1 2 3 4 5 6 7 |
|
Defined in active_support/core_ext/object/inclusion.rb.
in?
1 2 3 4 |
|
Extensions to Module
Defined in active_support/core_ext/module/attr_internal.rb.
Internal Attributes
Active Support defines the macros attr_internal_reader, attr_internal_writer, and attr_internal_accessor The macro attr_internal is a synonym for attr_internal_accessor:
1 2 3 4 5 6 7 8 9 |
|
Extensions to String
Defined in active_support/core_ext/string/filters.rb.
remove
1
|
|
squish
The method squish strips leading and trailing whitespace, and substitutes runs of whitespace with a single space each:
1
|
|
truncate
1 2 |
|
Ellipsis can be customized with the :omission option
1 2 |
|
Note in particular that truncation takes into account the length of the omission string. Pass a :separator to truncate the string at a natural break:
1 2 3 4 |
|
Defined in active_support/core_ext/string/starts_ends_with.rb.
starts_with? and ends_with?
1 2 |
|
Defined in active_support/core_ext/string/access.rb.
at(position)
1 2 3 4 |
|
from(position)
1 2 3 4 |
|
to(position)
1 2 3 4 |
|
Defined in active_support/core_ext/string/conversions.rb.
to_date, to_time, to_datetime
1 2 3 4 5 6 |
|