Convert and array into a tuple.
Methods
- cast_from
- every
- every!
- json_check_circular
- json_shift
- json_transform
- mutable_methods
- restore_snapshot
- take_snapshot
- to_elementor
- to_elementor!
- to_json
- to_t
Public Class methods
[ show source ]
# File lib/facets/more/typecast.rb, line 124 def cast_from(object, options={}) retval = super return retval unless retval == nil return object.to_a if object.respond_to? :to_a end
[ show source ]
# File lib/facets/more/syncarray.rb, line 32 def self.mutable_methods @mutable ||= %w{ << []= abbrev clear collect! compact! concat delete delete_at delete_if fill flatten insert map! pop push reject! replace reverse! shift slice! sort! transpose uniq! unshift } end
Public Instance methods
[ show source ]
# File lib/facets/more/elementor.rb, line 75 def every Elementor.new( self, :array ) end
[ show source ]
# File lib/facets/more/elementor.rb, line 79 def every! Elementor.new( self, :inplace_array ) end
[ show source ]
# File lib/facets/more/snapshot.rb, line 140 def restore_snapshot(snap) replace(snap) end
[ show source ]
# File lib/facets/more/snapshot.rb, line 139 def take_snapshot() dup end
[ show source ]
# File lib/facets/more/elementor.rb, line 67 def to_elementor Elementor.new( self ) end
[ show source ]
# File lib/facets/more/elementor.rb, line 71 def to_elementor! Elementor.new( self, :inplace ) end
Returns a JSON string containing a JSON array, that is unparsed from this Array instance. state is a JSON::State object, that can also be used to configure the produced JSON string output further. depth is used to find out nesting depth, to indent accordingly.
[ show source ]
# File lib/facets/more/json.rb, line 545 def to_json(state = nil, depth = 0) state = JSON::State.from_state(state) json_check_circular(state) { json_transform(state, depth) } end
[ show source ]
# File lib/facets/more/tuple.rb, line 260 def to_t Tuple.cast_from_array( self ) end
Private Instance methods
[ show source ]
# File lib/facets/more/json.rb, line 552 def json_check_circular(state) if state state.seen?(self) and raise JSON::CircularDatastructure, "circular data structures not supported!" state.remember self end yield ensure state and state.forget self end
[ show source ]
# File lib/facets/more/json.rb, line 563 def json_shift(state, depth) state and not state.array_nl.empty? or return '' state.indent * depth end
[ show source ]
# File lib/facets/more/json.rb, line 568 def json_transform(state, depth) delim = ',' delim << state.array_nl if state result = '[' result << state.array_nl if state result << map { |value| json_shift(state, depth + 1) << value.to_json(state, depth + 1) }.join(delim) result << state.array_nl if state result << json_shift(state, depth) result << ']' result end