Class: WarningHash

Inherits:
Hash show all
Defined in:
lib/ontomde-core/context.rb

Overview

Internal use.

Used for storing context.

Instance Method Summary collapse

Instance Method Details

#[](key, default = Object.class) ⇒ Object

Returns context value associated to key.

Raises an error if key is not found. Returns default, when context is undefined for key, and a default value is provided. if value is missing, key is return when context is true. (feature used by web inspector)

Raises:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ontomde-core/context.rb', line 16

def [](key,default=Object.class)
  val=super(key)
  return val unless val.nil?
  #Note: Object.class is used as a magic number.
  return default unless default==Object.class
  return "#{key}" if self[:contextReturnKeyIfEmpty,false]
  raise Warning.new(), <<FINCODE
Evaluation interrompue:
La session ne contient pas la variable :#{key}.
L'exemple de code suivant permet de definir une variable de contexte:

votre code
mtk_context(:#{key}=>'valeur'){
   votre code
   puts context[:#{key}]
   votre code
   }
FINCODE
end

#get(key) ⇒ Object



35
36
37
38
# File 'lib/ontomde-core/context.rb', line 35

def get(key)
  return self[key] if self.include?(key)
  return nil
end