Class: JavascriptHash

Inherits:
JavascriptObject show all
Includes:
Enumerable
Defined in:
lib/vapir-firefox/javascript_object.rb

Overview

this class represents a hash, or ‘object’ type in javascript.

Instance Attribute Summary

Attributes inherited from JavascriptObject

#debug_name, #firefox_socket, #function_result, #ref

Instance Method Summary collapse

Methods inherited from JavascriptObject

#%, #*, #+, #-, #/, #<, #<=, #==, #>, #>=, #[], #[]=, always_define_methods, always_define_methods=, #assign, #assign_expr, #assign_or_call_or_val_or_object_by_suffix, #attr, #binary_operator, #call, #define_methods!, #implemented_interfaces, #initialize, #inspect, #instanceof, #invoke, #invoke?, #method_missing, #new, #object_respond_to?, #object_type, #pass, #pretty_print, #respond_to?, #store, #store_rand_object_key, #store_rand_temp, #sub, #to_array, #to_dom, #to_function, #to_hash, #to_js_array, #to_js_hash, #to_js_hash_safe, #to_ruby_array, #to_ruby_hash, #to_simple_enumerator, #triple_equals, #type, #val, #val_or_object, #val_str

Constructor Details

This class inherits a constructor from JavascriptObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class JavascriptObject

Instance Method Details

#each(&block) ⇒ Object

yields each key and value



709
710
711
712
713
714
715
716
717
# File 'lib/vapir-firefox/javascript_object.rb', line 709

def each(&block) # :yields: key, value
  keys.each do |key|
    if block.arity==1
      yield [key, self[key]]
    else
      yield key, self[key]
    end
  end
end

#each_pairObject

yields each key and value for this object



719
720
721
722
723
# File 'lib/vapir-firefox/javascript_object.rb', line 719

def each_pair
  each do |key,value|
    yield key,value
  end
end

#key?(key) ⇒ Boolean

returns whether the given key is a defined key of this javascript object

Returns:

  • (Boolean)


705
706
707
# File 'lib/vapir-firefox/javascript_object.rb', line 705

def key?(key)
  firefox_socket.call_function(:obj => self, :key => key){ "return key in obj;" }
end

#keysObject

returns an array of keys of this javascript object



701
702
703
# File 'lib/vapir-firefox/javascript_object.rb', line 701

def keys
  @keys=firefox_socket.call_function(:obj => self){ "var keys=[]; for(var key in obj) { keys.push(key); } return keys;" }.val
end