Sha256: fd1fff3193a532add81315c9e77b93f405a1966899696f73131196dad36b90a8

Contents?: true

Size: 906 Bytes

Versions: 3

Compression:

Stored size: 906 Bytes

Contents

# encoding: utf-8
require_relative "base"

module Hexx
  module Creators

    # @api hide
    # Adds setter and getter for the instance parameter.
    #
    # @example
    #   # Providing that MyClass#params returns a hash
    #   Parameter.add MyClass, :name
    #   object = MyClass.new
    #
    #   object.params["name"] # => nil
    #   object.name           # => nil
    #
    #   object.params["name"] = "Ivan"
    #   object.params["name"] # => "Ivan"
    #   object.name           # => "Ivan"
    #
    #   object.name = "Ivo"
    #   object.params["name"] # => "Ivo"
    #   object.name           # => "Ivo"
    class Parameter < Base

      private

      # @api hide
      def setter
        "private def #{ name }; params[\"#{ name }\"]; end"
      end

      # @api hide
      def getter
        "private def #{ name }=(value); params[\"#{ name }\"] = value; end"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hexx-7.1.0 lib/hexx/creators/parameter.rb
hexx-7.0.1 lib/hexx/creators/parameter.rb
hexx-7.0.0 lib/hexx/creators/parameter.rb