Class: Array

Inherits:
Object show all
Defined in:
lib/rfm/utilities/sax_parser.rb,
lib/rfm/utilities/core_ext.rb

Overview

Object

Direct Known Subclasses

Rfm::CompoundQuery, Rfm::Resultset

Instance Method Summary collapse

Instance Method Details

#_merge_object!(obj, name, delimiter, prefs, type, options = {}) ⇒ Object


1042
1043
1044
1045
1046
1047
1048
1049
# File 'lib/rfm/utilities/sax_parser.rb', line 1042

def _merge_object!(obj, name, delimiter, prefs, type, options={})
	#puts ["\n+++++ARRAY._merge_object", self.class, (obj.to_s rescue obj.class), name, delimiter, prefs, type, options].join(', ')
	case
	when prefs=='shared' || type == 'attribute' && prefs.to_s != 'private' ; _merge_shared!(obj, name, delimiter, prefs, type, options)
	when prefs=='private'; _merge_instance!(obj, name, delimiter, prefs, type, options)
	else self << obj
	end
end

#rfm_extend_member(member, extension, i = nil) ⇒ Object


102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/rfm/utilities/core_ext.rb', line 102

def rfm_extend_member(member, extension, i=nil)
	if member and extension
   unless member.instance_variable_get(:@root)
	  member.instance_variable_set(:@root, @root)
	  member.instance_variable_set(:@parent, self)
	  member.instance_variable_set(:@index, i)
 		member.instance_eval(){def root; @root; end}
 		member.instance_eval(){def parent; @parent; end}
 		member.instance_eval(){def get_index; @index; end}
 	end
	member.extend(extension)
end  
end

#rfm_extend_members(klass, caller = nil) ⇒ Object

These methods allow dynamic extension of array members with other modules. These methods also carry the @root object for reference, when you don't have the root object explicity referenced anywhere.

These methods might slow down array traversal, as they add interpreted code to methods that were otherwise pure C.


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/rfm/utilities/core_ext.rb', line 73

def rfm_extend_members(klass, caller=nil)
	@parent = caller
  @root = caller.instance_variable_get(:@root)
	@member_extension = klass
	self.instance_eval do
	  class << self
	  	attr_accessor :parent
	
  		alias_method 'old_reader', '[]'
  		def [](*args)
  			member = old_reader(*args)
        rfm_extend_member(member, @member_extension, args[0]) if args[0].is_a? Integer
  			member
  		end

  		alias_method 'old_each', 'each'
  		def each
  			i = -1
  			old_each do |member|
  				i = i + 1
  				rfm_extend_member(member, @member_extension, i)
  				yield(member)
  			end
  		end
	  end
	end unless defined? old_reader
	self
end

#rfm_extract_options!Object

Taken from ActiveSupport extract_options!.


63
64
65
# File 'lib/rfm/utilities/core_ext.rb', line 63

def rfm_extract_options!
  last.is_a?(::Hash) ? pop : {}
end