Class: Peruby::Ref
- Inherits:
-
Object
- Object
- Peruby::Ref
- Defined in:
- lib/peruby/runtime/ref.rb
Overview
Perl reference with an optional blessed package.
Instance Attribute Summary collapse
-
#blessed ⇒ Object
Returns the value of attribute blessed.
-
#runtime ⇒ Object
Returns the value of attribute runtime.
Instance Method Summary collapse
-
#initialize(target, blessed = nil) ⇒ Ref
constructor
A new instance of Ref.
- #kind ⇒ Object
- #ref_string ⇒ Object
- #target ⇒ Object
- #weak? ⇒ Boolean
- #weaken! ⇒ Object
Constructor Details
#initialize(target, blessed = nil) ⇒ Ref
Returns a new instance of Ref.
10 11 12 13 14 |
# File 'lib/peruby/runtime/ref.rb', line 10 def initialize(target, blessed = nil) @target = target @blessed = blessed @weak = false end |
Instance Attribute Details
#blessed ⇒ Object
Returns the value of attribute blessed.
8 9 10 |
# File 'lib/peruby/runtime/ref.rb', line 8 def blessed @blessed end |
#runtime ⇒ Object
Returns the value of attribute runtime.
8 9 10 |
# File 'lib/peruby/runtime/ref.rb', line 8 def runtime @runtime end |
Instance Method Details
#kind ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/peruby/runtime/ref.rb', line 30 def kind value = target return 'REF' if value.is_a?(Scalar) && value.get.is_a?(Ref) kinds = { Scalar => 'SCALAR', PerlArray => 'ARRAY', PerlHash => 'HASH', Glob => 'GLOB', Regexp => 'Regexp', Code => 'CODE' } kinds.fetch(value.class, nil) end |
#ref_string ⇒ Object
39 40 41 |
# File 'lib/peruby/runtime/ref.rb', line 39 def ref_string @blessed || kind end |
#target ⇒ Object
16 17 18 19 20 |
# File 'lib/peruby/runtime/ref.rb', line 16 def target @weak ? @target.__getobj__ : @target rescue WeakRef::RefError nil end |
#weak? ⇒ Boolean
28 |
# File 'lib/peruby/runtime/ref.rb', line 28 def weak? = @weak |
#weaken! ⇒ Object
22 23 24 25 26 |
# File 'lib/peruby/runtime/ref.rb', line 22 def weaken! @target = WeakRef.new(@target) @weak = true self end |