Class: Peruby::Stash
- Inherits:
-
Object
- Object
- Peruby::Stash
- Defined in:
- lib/peruby/runtime/stash.rb
Overview
Rooted Perl package symbol table.
Instance Attribute Summary collapse
-
#generation ⇒ Object
readonly
Returns the value of attribute generation.
Instance Method Summary collapse
- #fetch(name) ⇒ Object
- #glob(name) ⇒ Object
-
#initialize ⇒ Stash
constructor
A new instance of Stash.
- #symbols(package = 'main') ⇒ Object
- #touch ⇒ Object
Constructor Details
#initialize ⇒ Stash
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
#generation ⇒ Object (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 |
#touch ⇒ Object
31 32 33 |
# File 'lib/peruby/runtime/stash.rb', line 31 def touch @generation += 1 end |