Class Class
In: lib/facets/more/classmethods.rb
lib/facets/more/typecast.rb
lib/facets/more/json.rb
lib/facets/more/preinitialize.rb
lib/facets/more/ormsupport.rb
lib/facets/more/cut.rb
lib/facets/core/module/class_extension.rb
lib/facets/core/module/prepend.rb
lib/facets/core/module/module_load.rb
lib/facets/core/class/unix_path.rb
lib/facets/core/class/cattr.rb
lib/facets/core/class/remove_descendents.rb
lib/facets/core/class/descendents.rb
lib/facets/core/class/method_name.rb
lib/facets/core/class/to_proc.rb
Parent: Object
Credit:Daniel Schierbeck

Methods

Included Modules

ORMSupport

External Aliases

from_string -> from_symbol
new -> postinitialize_new
basename -> demodulize
allocate -> _allocate_without_cut
module_load -> class_load
module_require -> class_require

Public Class methods

"string".cast_to Class #=> String

Public Instance methods

_new_without_cut(*args, &blk)

Alias for new

Creates a class-variable attribute that can be accessed both on an instance and class level.

NOTE These used to be a Module methods. But turns out these to work as expected when included. The class-level method is not carried along. So the are now just class methods. Accordingly, mattr will eventually be deprecated so use cattr instead.

Creates a class-variable attr_accessor that can be accessed both on an instance and class level.

  class MyClass
    cattr_accessor :a
  end

  MyClass.a = 10
  MyClass.a           #=> 10
  mc = MyClass.new
  mc.a                #=> 10

Creates a class-variable attr_reader that can be accessed both on an instance and class level.

  class MyClass
    @@a = 10
    cattr_reader :a
  end

  MyClass.a           #=> 10
  MyClass.new.a       #=> 10

Creates a class-variable attr_writer that can be accessed both on an instance and class level.

  class MyClass
    cattr_writer :a
    def a
      @@a
    end
  end

  MyClass.a = 10
  MyClass.a            #=> 10
  MyClass.new.a = 29
  MyClass.a            #=> 29

List of cuts in outer to inner order. Eg.

  [ Cut2, Cut1 ]

Returns true, if this class can be used to create an instance from a serialised JSON string. The class has to implement a class method json_create that expects a hash as first parameter, which includes the required data.

mattr( *syms )

Alias for cattr

mattr_accessor(*syms)

Alias for cattr_accessor

mattr_reader( *syms )

Alias for cattr_reader

mattr_writer(*syms)

Alias for cattr_writer

When a method is added, check to see if cut applies to it, and if so join it.

Converts a class name to a suitable method name

  My::ClassName.method_name => "my__class_name"

Inspired by facets/core/string/underscore.

predecessors()

Alias for cuts

Prepend an aspect module to a class.

class Firetruck

  def put_out_fire(option)
    "Put out #{option}"
  end

end

module FastFiretruck

  def put_out_fire(option)
    super("very #{option}!")
  end

end

Firetruck.prepend(FastFiretruck)

ft = Firetruck.new ft.put_out_fire(‘fast’) #=> "Put out very fast!"

Master cutting class (contains all cuts)

protected

remove_subclasses()

Alias for remove_descendents

subclasses()

Alias for descendents

Convert instatiation of a class into a Proc.

 class Person
    def initialize(name)
      @name = name
    end

    def inspect
      @name.to_str
    end
  end

  %w(john bob jane hans).map(&Person) => [john, bob, jane, hans]

Converts a class name to a unix path

  My::ClassName.unix_path => "/my/class_name"

Inspired by facets/core/string/underscore.

[Validate]