Module: Clojure::Metadata

Included in:
List, Map, Set, Vector
Defined in:
lib/clj/types.rb

Instance Method Summary collapse

Instance Method Details

#metadataObject


18
19
20
# File 'lib/clj/types.rb', line 18

def 
	@metadata ||= Clojure::Map.new
end

#metadata=(value) ⇒ Object


22
23
24
25
26
27
28
29
# File 'lib/clj/types.rb', line 22

def metadata= (value)
	.merge! case value
		when ::Hash   then value
		when ::Symbol then { value => true }
		when ::String then { :tag => value }
		else raise ArgumentError, 'the passed value is not suitable as metadata'
	end
end

#metadata_to_clj(options = {}) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/clj/types.rb', line 31

def  (options = {})
	return '' unless options[:metadata] != false && @metadata && !@metadata.empty?

	'^' + if @metadata.length == 1
		piece = @metadata.first

		if piece.first.is_a?(::Symbol) && piece.last == true
			piece.first.to_clj(options)
		elsif piece.first == :tag && piece.last.is_a?(::String)
			piece.last.to_clj(options)
		else
			@metadata.to_clj(options)
		end
	else
		@metadata.to_clj(options)
	end + ' '
end