Sha256: 40fd6ff5bf3d8280259c4ed83580f07a4e88969f597fbd0d6ce956a3b2896ef7

Contents?: true

Size: 652 Bytes

Versions: 1

Compression:

Stored size: 652 Bytes

Contents

module NamedAccessors
  module Utilities
    private
    def getter_name(options)
      extract_as_option(options)
    end

    def setter_name(options)
      :"#{extract_as_option(options)}="
    end

    def extract_as_option(options)
      options.fetch(:as) rescue raise "You must specify `as` option"
    end

    def instance_variable_name(name)
      :"@#{name}"
    end

    def extract_accessor_options(options)
      [extract_option(options, :reader), extract_option(options, :writer)]
    end

    def extract_option(options, type)
      option = options.fetch(type, nil)

      option ? options.merge(as: option) : options
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
named_accessors-1.1 lib/named_accessors/utilities.rb