Sha256: e47da589dbdd5bb315f455f91d486bfca5c5b5078e6a562d82e90a82ee997506

Contents?: true

Size: 730 Bytes

Versions: 8

Compression:

Stored size: 730 Bytes

Contents

class SugarPNG
  module DynAccessor
    def dyn_accessor *names
      names.each do |name|
        if name.is_a?(Hash)
          # dynamic accessor with alias(es)
          name.each do |main, aliases|
            dyn_accessor main
            Array(aliases).each do |aliased|
              class_eval <<-EOF
                alias :#{aliased}  :#{main}
                alias :#{aliased}= :#{main}=
              EOF
            end
          end
        else
          attr_writer name
          # dynamic getter or setter based on argument given or not
          class_eval <<-EOF
            def #{name} arg=nil
              arg ? @#{name} = arg : @#{name}
            end
          EOF
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sugar_png-0.5.5 lib/sugar_png/dyn_accessor.rb
sugar_png-0.5.4 lib/sugar_png/dyn_accessor.rb
sugar_png-0.5.3 lib/sugar_png/dyn_accessor.rb
sugar_png-0.5.2 lib/sugar_png/dyn_accessor.rb
sugar_png-0.5.1 lib/sugar_png/dyn_accessor.rb
sugar_png-0.5.0 lib/sugar_png/dyn_accessor.rb
sugar_png-0.4.1 lib/sugar_png/dyn_accessor.rb
sugar_png-0.4.0 lib/sugar_png/dyn_accessor.rb