lib/bindata/base.rb in bindata-2.4.15 vs lib/bindata/base.rb in bindata-2.5.0

- old
+ new

@@ -15,11 +15,11 @@ class << self # Instantiates this class and reads from +io+, returning the newly # created data object. +args+ will be used when instantiating. def read(io, *args, &block) - obj = self.new(*args) + obj = new(*args) obj.read(io, &block) obj end # The arg processor for this class. @@ -46,11 +46,11 @@ def unregister_self RegisteredClasses.unregister(name) end # Registers all subclasses of this class for use - def register_subclasses #:nodoc: + def register_subclasses # :nodoc: singleton_class.send(:undef_method, :inherited) define_singleton_method(:inherited) do |subclass| RegisteredClasses.register(subclass.name, subclass) register_subclasses end @@ -88,10 +88,12 @@ attr_accessor :parent protected :parent= # Creates a new data object based on this instance. # + # This implements the prototype design pattern. + # # All parameters will be be duplicated. Use this method # when creating multiple objects with the same parameters. def new(value = nil, parent = nil) obj = clone obj.parent = parent if parent @@ -115,12 +117,12 @@ value end end # Returns a lazy evaluator for this object. - def lazy_evaluator #:nodoc: - @lazy ||= LazyEvaluator.new(self) + def lazy_evaluator # :nodoc: + @lazy_evaluator ||= LazyEvaluator.new(self) end # Returns the parameter referenced by +key+. # Use this method if you are sure the parameter is not to be evaluated. # You most likely want #eval_parameter. @@ -175,11 +177,11 @@ io.string end # Returns the hexadecimal string representation of this data object. def to_hex(&block) - to_binary_s(&block).unpack('H*')[0] + to_binary_s(&block).unpack1('H*') end # Return a human readable representation of this data object. def inspect snapshot.inspect @@ -189,55 +191,43 @@ def to_s snapshot.to_s end # Work with Ruby's pretty-printer library. - def pretty_print(pp) #:nodoc: + def pretty_print(pp) # :nodoc: pp.pp(snapshot) end # Override and delegate =~ as it is defined in Object. def =~(other) snapshot =~ other end # Returns a user friendly name of this object for debugging purposes. def debug_name - if @parent - @parent.debug_name_of(self) - else - "obj" - end + @parent ? @parent.debug_name_of(self) : 'obj' end # Returns the offset (in bytes) of this object with respect to its most # distant ancestor. def abs_offset - if @parent - @parent.abs_offset + @parent.offset_of(self) - else - 0 - end + @parent ? @parent.abs_offset + @parent.offset_of(self) : 0 end # Returns the offset (in bytes) of this object with respect to its parent. def rel_offset - if @parent - @parent.offset_of(self) - else - 0 - end + @parent ? @parent.offset_of(self) : 0 end - def ==(other) #:nodoc: + def ==(other) # :nodoc: # double dispatch other == snapshot end # 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: + def safe_respond_to?(symbol, include_private = false) # :nodoc: base_respond_to?(symbol, include_private) end alias base_respond_to? respond_to? @@ -327,9 +317,8 @@ 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) - end + def sanitize_parameters!(obj_class, obj_params); end end end