Sha256: 6cabe9fda35975b4c5874952daa3f6a49aa76b35b78ee81158c3d19e03f6f461

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

# encoding: utf-8

class Object
  # The opposite of <tt>#nil?</tt>.
  #
  # @author Botanicus
  # @since 0.0.3
  # @return [true, false] True if self is nil, false otherwise
  def not_nil?
    not self.nil?
  end

  # Defines a instance method on class of the object.
  # 
  # @author Botanicus
  # @since 0.0.3
  # @param [Symbol] Method name
  # @param [Method, Proc, optional] +Method+ or +Proc+ which will be used as body of the method
  # @yield [block] Block which will be used as body of the method
  # @return [Object] First (and only) item of the array
  # @see <tt>Module#define_singleton_method</tt> for define method on singleton class
  # @example
  #   class Experiment
  #     def method_generator
  #       define_instance_method(:new_method) do |arg|
  #         puts "Method :new_method called with #{arg}"
  #       end
  #     end
  #   end
  #   Experiment.new.methods.include?(:new_method) # => false
  #   Experiment.new.method_generator
  #   Experiment.new.methods.include?(:new_method) # => true
  def define_instance_method(*args, &block)
    self.class.send(:define_method, *args, &block)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubyexts-0.3.pre lib/rubyexts/object.rb
rubyexts-0.0.2.1 lib/rubyexts/object.rb
rubyexts-0.0.2 lib/rubyexts/object.rb
rubyexts-0.1.pre lib/rubyexts/object.rb