Same as above, except in Object.

Methods
A
B
C
D
F
H
I
L
M
N
P
R
S
T
U
W
Included Modules
Constants
Dispatcher = ActionController::Dispatcher
 
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
 
RAILTIES_PATH = File.join(File.dirname(__FILE__), '..')
 
Class Public methods
blank_slate_method_added(name)
find_hidden_method(name)
# File activesupport/lib/active_support/vendor/builder-2.1.2/blankslate.rb, line 90
def find_hidden_method(name)
  nil
end
lookup_missing_generator(class_id)

Lookup missing generators using const_missing. This allows any generator to reference another without having to know its location: RubyGems, ~/.rails/generators, and RAILS_ROOT/generators.

# File railties/lib/rails_generator/lookup.rb, line 10
def lookup_missing_generator(class_id)
  if md = /(.+)Generator$/.match(class_id.to_s)
    name = md.captures.first.demodulize.underscore
    Rails::Generator::Base.lookup(name).klass
  else
    const_missing_before_generators(class_id)
  end
end
method_added(name)

Detect method additions to Object and remove them in the BlankSlate class.

Also aliased as: blank_slate_method_added
# File activesupport/lib/active_support/vendor/builder-2.1.2/blankslate.rb, line 83
def method_added(name)
  result = blank_slate_method_added(name)
  return result if self != Object
  BlankSlate.hide(name)
  result
end
Instance Public methods
acts_like?(duck)

A duck-type assistant method. For example, Active Support extends Date to define an acts_like_date? method, and extends Time to define acts_like_time?. As a result, we can do “x.acts_like?(:time)” and “x.acts_like?(:date)” to do duck-type-safe comparisons, since classes that we want to act like Time simply need to define an acts_like_time? method.

# File activesupport/lib/active_support/core_ext/object/misc.rb, line 89
def acts_like?(duck)
  respond_to? "acts_like_#{duck}?"
end
app(create=false)

reference the global “app” instance, created on demand. To recreate the instance, pass a non-false value as the parameter.

# File railties/lib/console_app.rb, line 9
def app(create=false)
  @app_integration_instance = nil if create
  @app_integration_instance ||= new_session do |sess|
    sess.host! "www.example.com"
  end
end
as_json(options = nil)
# File activesupport/lib/active_support/json/encoders/object.rb, line 7
def as_json(options = nil)
  instance_values
end
blank?()

An object is blank if it's false, empty, or a whitespace string. For example, “”, “ ”, nil, [], and {} are blank.

This simplifies:

if !address.nil? && !address.empty?

…to:

if !address.blank?
# File activesupport/lib/active_support/core_ext/object/blank.rb, line 12
def blank?
  respond_to?(:empty?) ? empty? : !self
end
class_eval(*args, &block)

#class_eval on an object acts like singleton_class_eval.

# File activesupport/lib/active_support/core_ext/object/singleton_class.rb, line 10
def class_eval(*args, &block)
  singleton_class.class_eval(*args, &block)
end
create_fixtures(*table_names, &block)
# File railties/lib/test_help.rb, line 24
def create_fixtures(*table_names, &block)
  Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names, {}, &block)
end
duplicable?()

Can you safely .dup this object? False for nil, false, true, symbols, and numbers; true otherwise.

# File activesupport/lib/active_support/core_ext/duplicable.rb, line 4
def duplicable?
  true
end
find_cmd(*commands)
# File railties/lib/commands/dbconsole.rb, line 33
def find_cmd(*commands)
  dirs_on_path = ENV['PATH'].to_s.split(File::PATH_SEPARATOR)
  commands += commands.map{|cmd| "#{cmd}.exe"} if RUBY_PLATFORM =~ /win32/
  full_path_command = nil
  found = commands.detect do |cmd|
    dir = dirs_on_path.detect do |path|
      full_path_command = File.join(path, cmd)
      File.executable? full_path_command
    end
  end
  found ? full_path_command : abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
end
helper()
# File railties/lib/console_with_helpers.rb, line 1
def helper
  @helper ||= ApplicationController.helpers
end
html_safe?()
# File activesupport/lib/active_support/core_ext/string/output_safety.rb, line 52
def html_safe?
  false
end
instance_exec(*args, &block)

Evaluate the block with the given arguments within the context of this object, so self is set to the method receiver.

From Mauricio's eigenclass.org/hiki/bounded+space+instance_exec

# File activesupport/lib/active_support/core_ext/object/extending.rb, line 63
def instance_exec(*args, &block)
  begin
    old_critical, Thread.critical = Thread.critical, true
    n = 0
    n += 1 while respond_to?(method_name = "__instance_exec#{n}")
    InstanceExecMethods.module_eval { define_method(method_name, &block) }
  ensure
    Thread.critical = old_critical
  end
  begin
    send(method_name, *args)
  ensure
    InstanceExecMethods.module_eval { remove_method(method_name) } rescue nil
  end
end
instance_variable_defined?(variable)
# File activesupport/lib/active_support/core_ext/object/instance_variables.rb, line 4
def instance_variable_defined?(variable)
  instance_variables.include?(variable.to_s)
end
instance_variable_names()
# File activesupport/lib/active_support/core_ext/object/instance_variables.rb, line 37
def instance_variable_names
  instance_variables.map { |var| var.to_s }
end
metaclass()

Get object's meta (ghost, eigenclass, singleton) class.

Deprecated in favor of #singleton_class.

# File activesupport/lib/active_support/core_ext/object/metaclass.rb, line 7
def metaclass
  class << self
    self
  end
end
new_session()

create a new session. If a block is given, the new session will be yielded to the block before being returned.

# File railties/lib/console_app.rb, line 18
def new_session
  session = ActionController::Integration::Session.new
  yield session if block_given?
  session
end
presence()

Returns object if it's present? otherwise returns nil. object.presence is equivalent to object.present? ? object : nil.

This is handy for any representation of objects where blank is the same as not present at all. For example, this simplifies a common check for HTTP POST/query parameters:

state   = params[:state]   if params[:state].present?
country = params[:country] if params[:country].present?
region  = state || country || 'US'

…becomes:

region = params[:state].presence || params[:country].presence || 'US'
# File activesupport/lib/active_support/core_ext/object/blank.rb, line 35
def presence
  self if present?
end
present?()

An object is present if it's not blank.

# File activesupport/lib/active_support/core_ext/object/blank.rb, line 17
def present?
  !blank?
end
reload!()

reloads the environment

# File railties/lib/console_app.rb, line 25
def reload!
  puts "Reloading..."
  Dispatcher.cleanup_application
  Dispatcher.reload_application
  true
end
returning(value)

Returns valueafter yielding valueto the block. This simplifies the process of constructing an object, performing work on the object, and then returning the object from a method. It is a Ruby-ized realization of the K combinator, courtesy of Mikael Brockman.

Examples

# Without returning
def foo
  values = []
  values << "bar"
  values << "baz"
  return values
end
foo # => ['bar', 'baz']
# returning with a local variable
def foo
  returning values = [] do
    values << 'bar'
    values << 'baz'
  end
end
foo # => ['bar', 'baz']
# returning with a block argument
def foo
  returning [] do |values|
    values << 'bar'
    values << 'baz'
  end
end
foo # => ['bar', 'baz']
# File activesupport/lib/active_support/core_ext/object/misc.rb, line 40
def returning(value)
  ActiveSupport::Deprecation.warn('Kernel#returning has been deprecated in favor of Object#tap.', caller)
  yield(value)
  value
end
singleton_class()

Returns the object's singleton class.

# File activesupport/lib/active_support/core_ext/object/singleton_class.rb, line 3
def singleton_class
  class << self
    self
  end
end
tap()

Yields xto the block, and then returns x. The primary purpose of this method is to “tap into” a method chain, in order to perform operations on intermediate results within the chain.

(1..10).tap { |x| puts "original: #{x.inspect}" }.to_a.
  tap    { |x| puts "array: #{x.inspect}" }.
  select { |x| x%2 == 0 }.
  tap    { |x| puts "evens: #{x.inspect}" }.
  map    { |x| x*x }.
  tap    { |x| puts "squares: #{x.inspect}" }
# File activesupport/lib/active_support/core_ext/object/misc.rb, line 56
def tap
  yield self
  self
end
to_json(options = nil)

Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info.

# File activesupport/lib/active_support/json/encoders/object.rb, line 3
def to_json(options = nil)
  ActiveSupport::JSON.encode(as_json(options))
end
to_param()
# File actionpack/lib/action_controller/routing/routing_ext.rb, line 2
def to_param
  to_s
end
to_query(key)

Converts an object into a string suitable for use as a URL query string, using the given keyas the param name.

Note: This method is defined as a default implementation for all Objects for #to_query to work.

# File activesupport/lib/active_support/core_ext/object/conversions.rb, line 11
def to_query(key)
  require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
  "#{CGI.escape(key.to_s)}=#{CGI.escape(to_param.to_s)}"
end
try(method, *args, &block)

Invokes the method identified by the symbol method, passing it any arguments and/or the block specified, just like the regular Ruby Object#senddoes.

Unlikethat method however, a NoMethodError exception will notbe raised and nilwill be returned instead, if the receiving object is a nilobject or NilClass.

Examples

Without try

@person && @person.name

or

@person ? @person.name : nil

With try

@person.try(:name)

tryalso accepts arguments and/or a block, for the method it is trying

Person.try(:find, 1)
@people.try(:collect) {|p| p.name}
# File activesupport/lib/active_support/core_ext/try.rb, line 25
def try(method, *args, &block)
  send(method, *args, &block)
end
unescape(str, escaped = @regexp[:ESCAPED])
# File activesupport/lib/active_support/core_ext/uri.rb, line 10
def unescape(str, escaped = @regexp[:ESCAPED])
  enc = (str.encoding == Encoding::US_ASCII) ? Encoding::UTF_8 : str.encoding
  str.gsub(escaped) { [$&[1, 2].hex].pack('C') }.force_encoding(enc)
end
with_options(options)

An elegant way to factor duplication out of options passed to a series of method calls. Each method called in the block, with the block variable as the receiver, will have its options merged with the default optionshash provided. Each method called on the block variable must take an options hash as its final argument.

with_options :order => 'created_at', :class_name => 'Comment' do |post|
  post.has_many :comments, :conditions => ['approved = ?', true], :dependent => :delete_all
  post.has_many :unapproved_comments, :conditions => ['approved = ?', false]
  post.has_many :all_comments
end

Can also be used with an explicit receiver:

map.with_options :controller => "people" do |people|
  people.connect "/people",     :action => "index"
  people.connect "/people/:id", :action => "show"
end
# File activesupport/lib/active_support/core_ext/object/misc.rb, line 80
def with_options(options)
  yield ActiveSupport::OptionMerger.new(self, options)
end