Class: Peruby::Stash

Inherits:
Object
  • Object
show all
Defined in:
lib/peruby/runtime/stash.rb

Overview

Rooted Perl package symbol table.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStash

Returns a new instance of Stash.



8
9
10
11
12
# File 'lib/peruby/runtime/stash.rb', line 8

def initialize
  @packages = Hash.new { |packages, name| packages[name] = {} }
  @names = {}
  @generation = 0
end

Instance Attribute Details

#generationObject (readonly)

Returns the value of attribute generation.



6
7
8
# File 'lib/peruby/runtime/stash.rb', line 6

def generation
  @generation
end

Instance Method Details

#fetch(name) ⇒ Object



22
23
24
25
# File 'lib/peruby/runtime/stash.rb', line 22

def fetch(name)
  package, symbol = split(name)
  @packages[package][symbol]
end

#glob(name) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/peruby/runtime/stash.rb', line 14

def glob(name)
  package, symbol = split(name)
  @packages[package][symbol] ||= begin
    @generation += 1
    Glob.new("#{package}::#{symbol}")
  end
end

#symbols(package = 'main') ⇒ Object



27
28
29
# File 'lib/peruby/runtime/stash.rb', line 27

def symbols(package = 'main')
  @packages[normalize_package(package)].dup
end

#touchObject



31
32
33
# File 'lib/peruby/runtime/stash.rb', line 31

def touch
  @generation += 1
end