lib/rant/rantvar.rb in rant-0.4.2 vs lib/rant/rantvar.rb in rant-0.4.4
- old
+ new
@@ -14,11 +14,11 @@
# thus it acts as a namespace.
#
# If you're looking for general info about Rant, read the
# README[link:files/README.html].
module Rant
- VERSION = '0.4.2'
+ VERSION = '0.4.4'
# Those are the filenames for rantfiles.
# Case matters!
RANTFILES = [ "Rantfile",
"rantfile",
@@ -50,11 +50,11 @@
def self.__rant_no_value__
@__rant_no_value__
end
module MetaUtils
- # Creates two accessor methods:
+ # Creates three accessor methods:
# obj.attr_name:: Return value of instance variable
# @attr_name
# obj.attr_name = val:: Set value instance variable
# @attr_name to val
# obj.attr_name val:: same as above
@@ -70,10 +70,28 @@
end
end
EOD
nil
end
+ # Creates three accessor methods:
+ # obj.attr_name?:: Return value, true or false
+ # obj.attr_name:: Set attribute to true
+ # obj.no_attr_name:: Set attribute to false
+ def rant_flag attr_name
+ attr_name = valid_attr_name attr_name
+ module_eval <<-EOD
+ def #{attr_name}?
+ @#{attr_name}
+ end
+ def #{attr_name}
+ @#{attr_name} = true
+ end
+ def no_#{attr_name}
+ @#{attr_name} = false
+ end
+ EOD
+ end
# Creates accessor methods like #rant_attr for the attribute
# attr_name. Additionally, values are converted with to_str
# before assignment to instance variables happens.
def string_attr attr_name
attr_name = valid_attr_name attr_name
@@ -311,9 +329,21 @@
end
def has_var?(vid)
!self[vid].nil?
end
+
+ def _set(vid, val) #:nodoc:
+ @store[vid] = val
+ end
+
+ def _get(vid) #:nodoc:
+ @store[vid]
+ end
+
+ def _init(vid, val) #:nodoc:
+ @store[vid] ||= val
+ end
end # class Space
module Constraint
def matches? val