Class: Keisan::Tokens::Group

Inherits:
Keisan::Token show all
Defined in:
lib/keisan/tokens/group.rb

Instance Attribute Summary collapse

Attributes inherited from Keisan::Token

#string

Instance Method Summary collapse

Methods inherited from Keisan::Token

#regex, regex, type, #type

Constructor Details

#initialize(string) ⇒ Group

Returns a new instance of Group.



6
7
8
9
# File 'lib/keisan/tokens/group.rb', line 6

def initialize(string)
  @string = string
  @sub_tokens = Tokenizer.new(string[1...-1]).tokens
end

Instance Attribute Details

#sub_tokensObject (readonly)

Returns the value of attribute sub_tokens.



4
5
6
# File 'lib/keisan/tokens/group.rb', line 4

def sub_tokens
  @sub_tokens
end

Instance Method Details

#group_typeObject

Either :round, :square



12
13
14
15
16
17
18
19
20
21
# File 'lib/keisan/tokens/group.rb', line 12

def group_type
  case string[0]
  when "("
    :round
  when "["
    :square
  when "{"
    :curly
  end
end