Sha256: d533be930ccd13c918dfda4ff682f5c821a8bc32285242b3082d54144dae3e68

Contents?: true

Size: 569 Bytes

Versions: 12

Compression:

Stored size: 569 Bytes

Contents

# frozen_string_literal: true

module Grumlin
  class Shortcut
    extend Forwardable

    attr_reader :name, :block

    def_delegator :@block, :arity
    def_delegator :@block, :source_location

    def initialize(name, lazy: true, &block)
      @name = name
      @lazy = lazy
      @block = block
    end

    def ==(other)
      @name == other.name && @block == other.block
    end

    def lazy?
      @lazy
    end

    # TODO: to_s, inspect, preview

    def apply(object, *args, **params)
      object.instance_exec(*args, **params, &@block)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
grumlin-0.23.0 lib/grumlin/shortcut.rb
grumlin-0.22.5 lib/grumlin/shortcut.rb
grumlin-0.22.4 lib/grumlin/shortcut.rb
grumlin-0.22.3 lib/grumlin/shortcut.rb
grumlin-0.22.2 lib/grumlin/shortcut.rb
grumlin-0.22.1 lib/grumlin/shortcut.rb
grumlin-0.22.0 lib/grumlin/shortcut.rb
grumlin-0.21.1 lib/grumlin/shortcut.rb
grumlin-0.21.0 lib/grumlin/shortcut.rb
grumlin-0.20.2 lib/grumlin/shortcut.rb
grumlin-0.20.1 lib/grumlin/shortcut.rb
grumlin-0.20.0 lib/grumlin/shortcut.rb