module Modernize::MapMethods

Public Class Methods

add(struct, field, block) click to toggle source

Adds a field based on the result of the block if the field doesn’t already exist.

# File lib/modernizer/map_methods.rb, line 7
def add(struct, field, block)
  h = struct.hash
  h[field] = struct.instance_exec(&block) if h[field].nil?
end
compute(struct, field, block) click to toggle source

Adds or updates a field passing the current value (if any) as a parameter to the block.

# File lib/modernizer/map_methods.rb, line 29
def compute(struct, field, block)
  h = struct.hash
  h[field] = struct.instance_exec(h[field], &block)
end
map(struct, field, block) click to toggle source

Maps an existing field passing the current value as a parameter to the block.

# File lib/modernizer/map_methods.rb, line 21
def map(struct, field, block)
  h = struct.hash
  h[field] = struct.instance_exec(h[field], &block) unless h[field].nil?
end
remove(struct, field, block) click to toggle source

Removes a field.

# File lib/modernizer/map_methods.rb, line 14
def remove(struct, field, block)
  struct.hash.delete(field)
end