Class | Object |
In: |
lib/ext/object.rb
lib/ext/metaclass.rb lib/inactive_support/core_ext/blank.rb |
Parent: | Object |
Lists methods unique to a class.
# File lib/ext/object.rb, line 8 def self.unique_methods (public_methods - Object.methods).sort.map(&:to_sym) end
Returns a list of arguments and an options hash. Source taken from RSpec.
# File lib/ext/object.rb, line 13 def args_and_opts(*args) options = Hash === args.last ? args.pop : {} return args, options end
An object is blank if it‘s nil, empty, or a whitespace string. For example, "", " ", nil, [], and {} are blank.
This simplifies
if !address.nil? && !address.empty?
to
if !address.blank?
# File lib/inactive_support/core_ext/blank.rb, line 9 def blank? respond_to?(:empty?) ? empty? : !self end
Defines an instance method within a class
# File lib/ext/metaclass.rb, line 14 def class_def name, &blk class_eval { define_method name, &blk } end
The hidden singleton lurks behind everyone
# File lib/ext/metaclass.rb, line 5 def metaclass; class << self; self; end; end