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

_new_without_cut allocate cattr cattr_accessor cattr_reader cattr_writer cuts descendents from_string inherited json_creatable? mattr mattr_accessor mattr_reader mattr_writer method_added method_name new new predecessors prepend proxycut proxycut! proxycut= remove_descendents remove_subclasses subclasses to_proc unix_path

### 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

from_string(string)

"string".cast_to Class #=> String

### Public Instance methods

_new_without_cut(*args, &blk)

Alias for new

allocate(*args,&block)
cattr( *syms )

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.

cattr_accessor(*syms)

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

cattr_reader( *syms )

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

cattr_writer(*syms)

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

cuts()

List of cuts in outer to inner order. Eg.

      [ Cut2, Cut1 ]

descendents()
inherited( base )
json_creatable?()

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

method_added( method )

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

method_name()

Converts a class name to a suitable method name

      My::ClassName.method_name => "my__class_name"

Inspired by facets/core/string/underscore.

new(*args, &blk)
new(*args,&block)
predecessors()

Alias for cuts

prepend( aspect )

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!"

proxycut()

Master cutting class (contains all cuts)

proxycut!()
proxycut=(pc)

protected

remove_descendents()
remove_subclasses()

Alias for remove_descendents

subclasses()

Alias for descendents

to_proc()

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]

unix_path()

Converts a class name to a unix path

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

Inspired by facets/core/string/underscore.

[Validate]