Sha256: 08f26511c4f6b125f7776e5b1acfaa99d7ef4085419a7c9cc901d8a6c0cf8d36

Contents?: true

Size: 1.63 KB

Versions: 23

Compression:

Stored size: 1.63 KB

Contents

# Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

require_relative 'definition'

module Decode
	module Language
		module Ruby
			# A Ruby-specific attribute.
			class Attribute < Definition
				# The short form of the attribute.
				# e.g. `attr :value`.
				def short_form
					case @node.type
					when :block
						"#{@name} { ... }"
					else
						@node.location.expression.source
					end
				end
				
				def long_form
					if @node.location.line == @node.location.last_line
						@node.location.expression.source
					else
						short_form
					end
				end
			end
		end
	end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
decode-0.18.5 lib/decode/language/ruby/attribute.rb
decode-0.18.4 lib/decode/language/ruby/attribute.rb
decode-0.18.3 lib/decode/language/ruby/attribute.rb
decode-0.18.2 lib/decode/language/ruby/attribute.rb
decode-0.18.1 lib/decode/language/ruby/attribute.rb
decode-0.18.0 lib/decode/language/ruby/attribute.rb
decode-0.17.3 lib/decode/language/ruby/attribute.rb
decode-0.17.2 lib/decode/language/ruby/attribute.rb
decode-0.17.1 lib/decode/language/ruby/attribute.rb
decode-0.17.0 lib/decode/language/ruby/attribute.rb
decode-0.16.0 lib/decode/language/ruby/attribute.rb
decode-0.15.4 lib/decode/language/ruby/attribute.rb
decode-0.15.3 lib/decode/language/ruby/attribute.rb
decode-0.15.2 lib/decode/language/ruby/attribute.rb
decode-0.15.1 lib/decode/language/ruby/attribute.rb
decode-0.15.0 lib/decode/language/ruby/attribute.rb
decode-0.14.1 lib/decode/language/ruby/attribute.rb
decode-0.14.0 lib/decode/language/ruby/attribute.rb
decode-0.13.0 lib/decode/language/ruby/attribute.rb
decode-0.12.0 lib/decode/language/ruby/attribute.rb