Class: YARD::Parser::Ruby::Legacy::Statement

Inherits:
Object
  • Object
show all
Defined in:
lib/yard/parser/ruby/legacy/statement.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tokens, block = nil, comments = nil) ⇒ Statement

Returns a new instance of Statement.



13
14
15
16
17
18
# File 'lib/yard/parser/ruby/legacy/statement.rb', line 13

def initialize(tokens, block = nil, comments = nil)
  @tokens = tokens
  @block  = block
  @comments = comments
  @comments_hash_flag = false
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



4
5
6
# File 'lib/yard/parser/ruby/legacy/statement.rb', line 4

def block
  @block
end

#commentsObject (readonly)

Returns the value of attribute comments.



4
5
6
# File 'lib/yard/parser/ruby/legacy/statement.rb', line 4

def comments
  @comments
end

#comments_hash_flagObject

Returns the value of attribute comments_hash_flag.



11
12
13
# File 'lib/yard/parser/ruby/legacy/statement.rb', line 11

def comments_hash_flag
  @comments_hash_flag
end

#comments_rangeObject

Returns the value of attribute comments_range.



5
6
7
# File 'lib/yard/parser/ruby/legacy/statement.rb', line 5

def comments_range
  @comments_range
end

#groupObject

Deprecated.

Groups are now defined by directives



9
10
11
# File 'lib/yard/parser/ruby/legacy/statement.rb', line 9

def group
  @group
end

#tokensObject (readonly)

Returns the value of attribute tokens.



4
5
6
# File 'lib/yard/parser/ruby/legacy/statement.rb', line 4

def tokens
  @tokens
end

Instance Method Details

#first_lineObject



20
21
22
# File 'lib/yard/parser/ruby/legacy/statement.rb', line 20

def first_line
  to_s.split(/\n/)[0]
end

#inspectObject



31
32
33
34
35
36
# File 'lib/yard/parser/ruby/legacy/statement.rb', line 31

def inspect
  l = line - 1
  to_s(false).split(/\n/).map do |text|
    "\t#{l += 1}:  #{text}"
  end.join("\n")
end

#lineFixnum

Returns the first line of Ruby source.

Returns:

  • (Fixnum)

    the first line of Ruby source



43
44
45
# File 'lib/yard/parser/ruby/legacy/statement.rb', line 43

def line
  tokens.first.line_no
end

#line_rangeRange<Fixnum>

Returns the first to last lines of Ruby source.

Returns:

  • (Range<Fixnum>)

    the first to last lines of Ruby source

Since:

  • 0.5.4



49
50
51
# File 'lib/yard/parser/ruby/legacy/statement.rb', line 49

def line_range
  tokens.first.line_no..tokens.last.line_no
end

#showObject



38
39
40
# File 'lib/yard/parser/ruby/legacy/statement.rb', line 38

def show
  "\t#{line}: #{first_line}"
end

#to_s(include_block = true) ⇒ Object Also known as: source



24
25
26
27
28
# File 'lib/yard/parser/ruby/legacy/statement.rb', line 24

def to_s(include_block = true)
  tokens.map do |token|
    RubyToken::TkBlockContents === token ? (include_block ? block.to_s : '') : token.text
  end.join
end