Module: RplLang::Words::StringAndList

Includes:
Types
Included in:
Rpl
Defined in:
lib/rpl/words/string-list.rb

Instance Method Summary collapse

Methods included from Types

new_object

Instance Method Details

#populate_dictionaryObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rpl/words/string-list.rb', line 8

def populate_dictionary
  super

  category = 'Strings and Lists'

  @dictionary.add_word( ['rev'],
                        category,
                        '( s -- s ) reverse string or list',
                        proc do
                          args = stack_extract( [[RplString, RplList]] )

                          @stack << if args[0].is_a?( RplString )
                                      Types.new_object( RplString, "\"#{args[0].value.reverse}\"" )
                                    else
                                      Types.new_object( args[0].class, "{ #{args[0].value.reverse.join(' ')} }" )
                                    end
                        end )
end