Sha256: 2742a55b1ab0d1da02243acac7f23fec8fd43503c5538512378da2b1c13b630d

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

class DynamicSlotObject : BasicObject {
  def initialize {
    @object = Object new
  }

  def object {
    @object
  }

  def unknown_message: m with_params: p {
    m to_s split: ":" . each_with_index: |slotname idx| {
      @object set_slot: slotname value: $ p[idx]
    }
  }
}

class DynamicKeyHash : BasicObject {
  def initialize: @deep (false) {
    @hash = <[]>
  }

  def hash {
    @hash
  }

  def unknown_message: m with_params: p {
    m to_s split: ":" . each_with_index: |slotname idx| {
      val = p[idx]
      if: @deep then: {
        match val {
          case Block -> val = val to_hash
        }
      }
      @hash[slotname to_sym]: val
    }
  }
}

class DynamicValueArray : BasicObject {
  def initialize {
    @arr = []
  }

  def array {
    @arr
  }

  def unknown_message: m with_params: p {
    if: (p size > 0) then: {
      subarr = []
      m to_s split: ":" . each_with_index: |slotname idx| {
        subarr << (slotname to_sym)
        subarr << (p[idx])
      }
      @arr << subarr
    } else: {
      @arr << (m to_s rest to_sym) # skip leading :
    }
    self
  }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fancy-0.6.0 lib/dynamic_slot_object.fy