Core Extensions require 'active_support/core_ext/object' All Core Extensions require 'active_support/core_ext' All Active Support require 'active_support/all' require 'active_support/core_ext/object/blank' Cherry-picking
specific object, Ruby inserts a new anonymous class into the inheritance hierarchy as a container to hold these types of methods. http://www.devalot.com/articles/2008/09/ruby-singleton anonymous class foobar = [ ] def foobar.say “Hello” end
class << self def two () 2 end end def three () 3 end self.singleton_methods # => ["two", "one"] self.class # => Class self # => Foo end • Practical Uses of Singleton Classes class method class method anonymous class
value for :id placeholder class User def to_param "#{id}-#{name.parameterize}" end end user_path(@user) # => "/users/357-john-smith" ➧ => The return value should not be escaped! overwriting
models: user: Dude attributes: user: login: "Handle" # will translate User attribute "login" as "Handle" http://guides.rubyonrails.org/i18n.html scope of i18n config/locales/en.yml
and Exceptions silence_warnings { Object.const_set "RAILS_DEFAULT_LOGGER", logger } silence_stream(STDOUT) do # STDOUT is silent here end quietly { system 'bundle install' } # If the user is locked the increment is lost, no big deal. suppress(ActiveRecord::StaleObjectError) do current_user.increment! :visits end $VERBOSE even in subprocesses silencing exceptions silencing streams