class Universa::Binder

Adapter for Universa Binder class which behaves like a ruby hash.

Constants

LOCAL_METHODS

Public Class Methods

of(*args) click to toggle source

Create hew Binder from any hash. Keys will be converted to strings.

# File lib/universa/binder.rb, line 23
def self.of *args
  invoke_static "of", *args
end

Public Instance Methods

[](key) click to toggle source

Get object by key. @param [Object] key key.to_s will be used (so use Symbols or Strings freely) @return [Object] or nil

# File lib/universa/binder.rb, line 18
def [](key)
  __getobj__.get(key.to_s)
end
[]=(key, value) click to toggle source

Set object for a key

@param [Object] key key.to_s will be used (so use Symbols or Strings freely) @param [Object] value

# File lib/universa/binder.rb, line 11
def []=(key, value)
  __getobj__.set(key.to_s, value)
end
binary(key) click to toggle source
# File lib/universa/binder.rb, line 32
def binary(key)
  __getobj__.getBinary(key)
end
each(&block) click to toggle source

Enumerates all binder entries with a required block @yield [key,value] pairs

# File lib/universa/binder.rb, line 71
def each &block
  keys.each {|k| block.call [k, __getobj__.get(k)]}
end
keys() click to toggle source

Retrieve binder keys

# File lib/universa/binder.rb, line 28
def keys
  __getobj__.keySet()
end
map(&block) click to toggle source

@return an array of values returned by the block @yield [key,value] pairs.

# File lib/universa/binder.rb, line 77
def map(&block)
  keys.map {|k| block.call [k, __getobj__.get(k)]}
end
method_missing(method_name, *args, &block) click to toggle source

Internal use only. Call remote method as needed. This is where all the magick comes from: it call remote get/set method

Calls superclass method
# File lib/universa/binder.rb, line 44
def method_missing(method_name, *args, &block)
  if respond_to_missing?(method_name, true)
    super
  else
    if method_name[-1] == '_'
      __getobj__.set(method_name[0..-1], args[0])
      args[0]
    else
      __getobj__.get(method_name)
    end
  end
end
respond_to_missing?(method_name, include_private = false) click to toggle source

Internal use only. Allow processing remote commands as local calls

# File lib/universa/binder.rb, line 37
def respond_to_missing?(method_name, include_private = false)
  l = method_name[-1]
  LOCAL_METHODS.include?(method_name) || l == '!' || l == '?'
end
to_a() click to toggle source

Converts binder to the array of [key, value] pairs, like with regular ruby hashes @return [Array(Array(String,Object))] array of [key,value] pairs.

# File lib/universa/binder.rb, line 65
def to_a
  map {|x| x}
end
to_h() click to toggle source

converts to a regular ruby hash

# File lib/universa/binder.rb, line 82
def to_h
  to_a.to_h
end
to_s() click to toggle source
# File lib/universa/binder.rb, line 59
def to_s
  to_h.to_s
end