afaur/ruby-nicefn

View on GitHub
lib/inst.rb

Summary

Maintainability
A
0 mins
Test Coverage
# Place the Inst module inside of a namespace
module Nicefn
  # Adds one-liner instance method/fn declaration capabilities for classes
  module Inst
    define_method(:cm) { |func, &blk| define_singleton_method(func, &blk) }

    define_method(:fn) { |func, &blk| define_method(func, &blk) }

    define_method(:fp) do |func, &blk|
      define_method(func, &blk)
      private func
    end

    define_method(:fs) do |func, &blk|
      define_method(func, &blk)
      protected func
    end
  end
end