Sha256: 3b6832ae2c157bfdcd9cc626aa244c2fd7a7f0f43570e38e8dd0b2b9eec108a0

Contents?: true

Size: 852 Bytes

Versions: 1

Compression:

Stored size: 852 Bytes

Contents

class Object


  class TryObject

    def initialize(original_object)
      @original_object = original_object
      
    end

    def method_missing(method, *args, &block)
      @original_object.send(method, *args, &block) if(@original_object.respond_to? method) 
    end
    
    # Hacky, Hacky, make all public private (we always want to call on @original_object)
    # new and alloc etc will automatically be ignored as they raise an exception
    public_instance_methods.each do |pub_method|
      begin ; private pub_method ; rescue NameError ; end
    end
    
  end

  
  # Tries to call the given method if it exists. If the method doesn't
  # exist, it will just return nil
  def try_call(*args, &block)
    if args.empty?
      TryObject.new(self)
    else
      self.send(*args, &block) if(self.respond_to?(args.first))
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
talia_core-0.7.0 lib/core_ext/object.rb