Class: Slim::LogicLess::Context::Scope Private

Inherits:
Object
  • Object
show all
Defined in:
lib/slim/logic_less/context.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

API:

  • private

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dict, lookup, parent = nil) ⇒ Scope

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Scope.

API:

  • private



60
61
62
# File 'lib/slim/logic_less/context.rb', line 60

def initialize(dict, lookup, parent = nil)
  @dict, @lookup, @parent = dict, lookup, parent
end

Instance Attribute Details

#dict=(value) ⇒ Object (writeonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



58
59
60
# File 'lib/slim/logic_less/context.rb', line 58

def dict=(value)
  @dict = value
end

#lookup ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



57
58
59
# File 'lib/slim/logic_less/context.rb', line 57

def lookup
  @lookup
end

Instance Method Details

#[](name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/slim/logic_less/context.rb', line 81

def [](name)
  @lookup.each do |lookup|
    case lookup
    when :method
      return @dict.public_send(name) if @dict.respond_to?(name, false)
    when :symbol
      return @dict[name] if has_key?(name)
    when :string
      return @dict[name.to_s] if has_key?(name.to_s)
    when :instance_variable
      var_name = "@#{name}"
      return @dict.instance_variable_get(var_name) if instance_variable?(var_name)
    end
  end
  @parent[name] if @parent
end

#lambda(name, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/slim/logic_less/context.rb', line 64

def lambda(name, &block)
  @lookup.each do |lookup|
    case lookup
    when :method
      return @dict.public_send(name, &block) if @dict.respond_to?(name, false)
    when :symbol
      return @dict[name].call(&block) if has_key?(name)
    when :string
      return @dict[name.to_s].call(&block) if has_key?(name.to_s)
    when :instance_variable
      var_name = "@#{name}"
      return @dict.instance_variable_get(var_name).call(&block) if instance_variable?(var_name)
    end
  end
  @parent.lambda(name, &block) if @parent
end

#to_s ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



98
99
100
# File 'lib/slim/logic_less/context.rb', line 98

def to_s
  @dict.to_s
end