lib/bindata/base.rb in bindata-2.3.3 vs lib/bindata/base.rb in bindata-2.3.4

- old
+ new

@@ -27,21 +27,21 @@ @arg_processor ||= nil if name @arg_processor = "#{name}_arg_processor".gsub(/(?:^|_)(.)/) { $1.upcase }.to_sym elsif @arg_processor.is_a? Symbol - @arg_processor = BinData::const_get(@arg_processor).new + @arg_processor = BinData.const_get(@arg_processor).new elsif @arg_processor.nil? @arg_processor = superclass.arg_processor else @arg_processor end end # The name of this class as used by Records, Arrays etc. def bindata_name - RegisteredClasses.underscore_name(self.name) + RegisteredClasses.underscore_name(name) end # Call this method if this class is abstract and not to be used. def unregister_self RegisteredClasses.unregister(name) @@ -107,11 +107,11 @@ # parameters given at object construction to be overridden. # # Returns nil if +key+ does not refer to any parameter. def eval_parameter(key, overrides = nil) value = get_parameter(key) - if value.is_a?(Symbol) or value.respond_to?(:arity) + if value.is_a?(Symbol) || value.respond_to?(:arity) lazy_evaluator.lazy_eval(value, overrides) else value end end @@ -237,22 +237,23 @@ # A version of +respond_to?+ used by the lazy evaluator. It doesn't # reinvoke the evaluator so as to avoid infinite evaluation loops. def safe_respond_to?(symbol, include_private = false) #:nodoc: base_respond_to?(symbol, include_private) end - alias_method :base_respond_to?, :respond_to? #:nodoc: + alias base_respond_to? respond_to? + #--------------- private def extract_args(args) self.class.arg_processor.extract_args(self.class, args) end - def start_read(&block) + def start_read top_level_set(:in_read, true) - block.call + yield ensure top_level_set(:in_read, false) end # Is this object tree currently being read? Used by BasePrimitive. @@ -264,11 +265,11 @@ top_level.instance_variable_set("@tl_#{sym}", value) end def top_level_get(sym) tl = top_level - tl.instance_variable_defined?("@tl_#{sym}") and + tl.instance_variable_defined?("@tl_#{sym}") && tl.instance_variable_get("@tl_#{sym}") end def top_level if parent.nil? @@ -303,33 +304,33 @@ [value, sanitized_params, parent] end # Separates the arguments passed to BinData::Base.new into # [value, parameters, parent]. Called by #extract_args. - def separate_args(obj_class, obj_args) + def separate_args(_obj_class, obj_args) args = obj_args.dup value = parameters = parent = nil - if args.length > 1 and args.last.is_a? BinData::Base + if args.length > 1 && args.last.is_a?(BinData::Base) parent = args.pop end - if args.length > 0 and args.last.is_a? Hash + if args.length > 0 && args.last.is_a?(Hash) parameters = args.pop end if args.length > 0 value = args.pop end parameters ||= @@empty_hash - return [value, parameters, parent] + [value, parameters, parent] end # Performs sanity checks on the given parameters. # This method converts the parameters to the form expected # by the data object. - def sanitize_parameters!(obj_class, obj_params) + def sanitize_parameters!(obj_class, obj_params) end end end