Class: Warg::Config::VariableSet
- Inherits:
-
Object
- Object
- Warg::Config::VariableSet
show all
- Defined in:
- lib/warg.rb
Defined Under Namespace
Classes: Property
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, context) ⇒ VariableSet
Returns a new instance of VariableSet.
1260
1261
1262
1263
1264
1265
|
# File 'lib/warg.rb', line 1260
def initialize(name, context)
@_name = name
@context = context
@properties = Set.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
|
# File 'lib/warg.rb', line 1297
def method_missing(name, *args, &block)
writer_name = name.to_s
reader_name = writer_name.chomp("=")
if reader_name !~ Property::REGEXP
super
elsif reader_name == writer_name && block.nil?
$stderr.puts "`#{@_name}.#{reader_name}' was accessed before it was defined"
nil
elsif writer_name.end_with?("=") or not block.nil?
value = block || args
extend Property.new(reader_name, *value)
end
end
|
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
1258
1259
1260
|
# File 'lib/warg.rb', line 1258
def context
@context
end
|
Instance Method Details
#copy(other) ⇒ Object
1279
1280
1281
1282
1283
1284
1285
|
# File 'lib/warg.rb', line 1279
def copy(other)
other.properties.each do |property_name|
value = other.instance_variable_get("@#{property_name}")
extend Property.new(property_name, value)
end
end
|
#define!(property_name) ⇒ Object
1275
1276
1277
|
# File 'lib/warg.rb', line 1275
def define!(property_name)
@properties << property_name.to_s
end
|
#defined?(property_name) ⇒ Boolean
1271
1272
1273
|
# File 'lib/warg.rb', line 1271
def defined?(property_name)
@properties.include?(property_name.to_s)
end
|
#to_h ⇒ Object
1287
1288
1289
1290
1291
|
# File 'lib/warg.rb', line 1287
def to_h
@properties.each_with_object({}) do |property_name, variables|
variables["#{@_name}_#{property_name}"] = send(property_name)
end
end
|