Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/active_support/dependencies.rb,
lib/active_support/core_ext/blank.rb,
lib/active_support/core_ext/object/misc.rb,
lib/active_support/core_ext/kernel/agnostics.rb,
lib/active_support/core_ext/object/extending.rb,
lib/active_support/vendor/builder/blankslate.rb
Overview
:nodoc:
Class Method Summary collapse
Instance Method Summary collapse
-
#`(command) ⇒ Object
Makes backticks behave (somewhat more) similarly on all platforms.
-
#blank? ⇒ Boolean
“”, “ ”, nil, [], and {} are blank.
- #copy_instance_variables_from(object, exclude = []) ⇒ Object
- #extend_with_included_modules_from(object) ⇒ Object
- #extended_by ⇒ Object
- #instance_exec(*arguments, &block) ⇒ Object
- #instance_values ⇒ Object
- #load(file, *extras) ⇒ Object
- #remove_subclasses_of(*superclasses) ⇒ Object
- #require(file, *extras) ⇒ Object
-
#returning(value) {|value| ... } ⇒ Object
A Ruby-ized realization of the K combinator, courtesy of Mikael Brockman.
- #subclasses_of(*superclasses) ⇒ Object
- #to_json ⇒ Object
- #with_options(options) {|ActiveSupport::OptionMerger.new(self, options)| ... } ⇒ Object
Class Method Details
.blank_slate_method_added ⇒ Object
46 |
# File 'lib/active_support/vendor/builder/blankslate.rb', line 46 alias_method :blank_slate_method_added, :method_added |
.method_added(name) ⇒ Object
47 48 49 50 51 |
# File 'lib/active_support/vendor/builder/blankslate.rb', line 47 def method_added(name) blank_slate_method_added(name) return if self != Object Builder::BlankSlate.hide(name) end |
Instance Method Details
#`(command) ⇒ Object
Makes backticks behave (somewhat more) similarly on all platforms. On win32 ‘nonexistent_command` raises Errno::ENOENT; on Unix, the spawned shell prints a message to stderr and sets $?. We emulate Unix on the former but not the latter.
6 7 8 9 10 |
# File 'lib/active_support/core_ext/kernel/agnostics.rb', line 6 def `(command) #:nodoc: super rescue Errno::ENOENT => e STDERR.puts "#$0: #{e}" end |
#blank? ⇒ Boolean
“”, “ ”, nil, [], and {} are blank
3 4 5 6 7 8 9 10 11 |
# File 'lib/active_support/core_ext/blank.rb', line 3 def blank? if respond_to?(:empty?) && respond_to?(:strip) empty? or strip.empty? elsif respond_to?(:empty?) empty? else !self end end |
#copy_instance_variables_from(object, exclude = []) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/active_support/core_ext/object/extending.rb', line 24 def copy_instance_variables_from(object, exclude = []) exclude += object.protected_instance_variables if object.respond_to? :protected_instance_variables instance_variables = object.instance_variables - exclude.map { |name| name.to_s } instance_variables.each { |name| instance_variable_set(name, object.instance_variable_get(name)) } end |
#extend_with_included_modules_from(object) ⇒ Object
31 32 33 |
# File 'lib/active_support/core_ext/object/extending.rb', line 31 def extend_with_included_modules_from(object) object.extended_by.each { |mod| extend mod } end |
#extended_by ⇒ Object
19 20 21 22 |
# File 'lib/active_support/core_ext/object/extending.rb', line 19 def extended_by ancestors = class << self; ancestors end ancestors.select { |mod| mod.class == Module } - [ Object, Kernel ] end |
#instance_exec(*arguments, &block) ⇒ Object
43 44 45 |
# File 'lib/active_support/core_ext/object/extending.rb', line 43 def instance_exec(*arguments, &block) block.bind(self)[*arguments] end |
#instance_values ⇒ Object
35 36 37 38 39 40 |
# File 'lib/active_support/core_ext/object/extending.rb', line 35 def instance_values instance_variables.inject({}) do |values, name| values[name[1..-1]] = instance_variable_get(name) values end end |
#load(file, *extras) ⇒ Object
139 140 141 142 143 144 |
# File 'lib/active_support/dependencies.rb', line 139 def load(file, *extras) super(file, *extras) rescue Object => exception exception.blame_file! file raise end |
#remove_subclasses_of(*superclasses) ⇒ Object
2 3 4 |
# File 'lib/active_support/core_ext/object/extending.rb', line 2 def remove_subclasses_of(*superclasses) Class.remove_class(*subclasses_of(*superclasses)) end |
#require(file, *extras) ⇒ Object
146 147 148 149 150 151 |
# File 'lib/active_support/dependencies.rb', line 146 def require(file, *extras) super(file, *extras) rescue Object => exception exception.blame_file! file raise end |
#returning(value) {|value| ... } ⇒ Object
A Ruby-ized realization of the K combinator, courtesy of Mikael Brockman.
def foo
returning values = [] do
values << 'bar'
values << 'baz'
end
end
foo # => ['bar', 'baz']
def foo
returning [] do |values|
values << 'bar'
values << 'baz'
end
end
foo # => ['bar', 'baz']
22 23 24 25 |
# File 'lib/active_support/core_ext/object/misc.rb', line 22 def returning(value) yield(value) value end |
#subclasses_of(*superclasses) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/active_support/core_ext/object/extending.rb', line 6 def subclasses_of(*superclasses) subclasses = [] ObjectSpace.each_object(Class) do |k| next if # Exclude this class if (k.ancestors & superclasses).empty? || # It's not a subclass of our supers superclasses.include?(k) || # It *is* one of the supers eval("! defined?(::#{k})") || # It's not defined. eval("::#{k}").object_id != k.object_id subclasses << k end subclasses end |
#to_json ⇒ Object
31 32 33 |
# File 'lib/active_support/core_ext/object/misc.rb', line 31 def to_json ActiveSupport::JSON.encode(self) end |
#with_options(options) {|ActiveSupport::OptionMerger.new(self, options)| ... } ⇒ Object
27 28 29 |
# File 'lib/active_support/core_ext/object/misc.rb', line 27 def () yield ActiveSupport::OptionMerger.new(self, ) end |