Skip to content

Instantly share code, notes, and snippets.

View piktur's full-sized avatar

daniel piktur

  • Sydney, Australia
View GitHub Profile
@piktur
piktur / introspection.rb
Last active July 27, 2018 02:23
Extension | Provides optimised Module introspection
# frozen_string_literal: true
require 'active_support/core_ext/module/introspection'
# Optimised `Module` introspection algorithm.
#
# @example Usage
# Support.install(:module)
#
# @see https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/module/introspection.rb
@piktur
piktur / constructor.rb
Last active July 27, 2018 00:43
Tools | An enumerable map
# frozen_string_literal: true
class Enum
# @param [Symbol] name The collection name
# @param [Hash] options
#
# @option options [Module] :namespace (Object) the parent module
# @option options [Symbol] :predicates (nil) the enumerated attribute name
# @option options [Symbol] :i18n_scope (nil)
@piktur
piktur / object.rb
Last active July 26, 2018 23:58
Extension | Provides safe constant assignment methods
# frozen_string_literal: true
module Support
# @example Usage
# Support.install(:object)
#
# module Abc
# safe_const_get(:XYZ) # => nil
# safe_const_set(:XYZ, 123) # => 123