class Universa::Binder
Adapter for Universa
Binder
class which behaves like a ruby hash.
Constants
- LOCAL_METHODS
Public Class Methods
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
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
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
# File lib/universa/binder.rb, line 32 def binary(key) __getobj__.getBinary(key) end
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
Retrieve binder keys
# File lib/universa/binder.rb, line 28 def keys __getobj__.keySet() end
@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
Internal use only. Call remote method as needed. This is where all the magick comes from: it call remote get/set 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
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
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
converts to a regular ruby hash
# File lib/universa/binder.rb, line 82 def to_h to_a.to_h end
# File lib/universa/binder.rb, line 59 def to_s to_h.to_s end