Elk is an object system for Python inspired by Moose for Perl. It implements many of the features of Moose including:
- attribute delegation
- default attribute values
- lazy attribute initialisation
- read-only attributes
- required attributes
- attribute type constraints
- roles
- method modifiers
Using python Syntax Highlighting
- import elk
- class Point(elk.Elk):
- x = elk.ElkAttribute(mode='rw', type=int)
- y = elk.ElkAttribute(mode='rw', type=int)
- def clear(self):
- self.x = 0
- self.y = 0
- class Point3D(Point):
- z = elk.ElkAttribute(mode='rw', type=int)
- @elk.after('clear')
- def clear_z(self):
- self.z = 0
Coloreado en 0.005 segundos, usando GeSHi 1.0.8.4
Ruby: MooseX
A postmodern object DSL for Ruby. MooseX is a toolbox to create Classes based on DSL, with unique features like
- method delegation and currying ( see 'handles')
- lazy attributes
- roles / abstract classes / interfaces
- traits / monads
- plugins
- parameterized roles
- composable type check
- events
Using ruby Syntax Highlighting
- require 'moosex'
- class Point
- include MooseX
- has x: {
- is: :rw, # read-write (mandatory)
- isa: Integer, # should be Integer
- default: 0, # default value is 0 (constant)
- }
- has y: {
- is: :rw,
- isa: Integer,
- default: -> { 0 }, # you should specify a lambda
- }
- def clear!
- self.x= 0 # to run with type-check you must
- self.y= 0 # use the setter instad @x=
- end
- def to_s
- "Point[x=#{self.x}, y=#{self.y}]"
- end
- end
- # now you have a generic constructor
- p1 = Point.new # x and y will be 0
- p2 = Point.new( x: 5 ) # y will be 0
- p3 = Point.new( x: 5, y: 4)
Coloreado en 0.003 segundos, usando GeSHi 1.0.8.4
JavaScript: o.js
If you like the rich OO features of other languages, such as Perl and Java, and wish you had the same power in JavaScript, but with a small footprint, then o.js is for you.
Using javascript Syntax Highlighting
- var Person = new o.Class({
- attributes: {
- name: { type:o.nonEmptyStringType },
- age: { type:o.integerType }
- },
- methods: {
- log_name: function () {
- console.log( this.name() );
- }
- }
- });
- var baggins = new Person({
- name: 'Bilbo',
- age: 111
- });
- baggins.log_name();
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4
Javascript: Joose
Joose is a self-hosting meta object system for JavaScript with support for classes, inheritance, mixins, traits, method modifiers and more.
Using javascript Syntax Highlighting
- Class("Point", {
- has: {
- x: {is: "ro"},
- y: {is: "rw"},
- },
- methods: {
- clear: function () {
- this.x = 0;
- this.setY(0);
- }
- }
- })
- Class("Point3D", {
- isa: Point,
- has: {
- z: {}
- },
- after: {
- clear: function () {
- this.z = 0;
- }
- }
- })
- var point = new Point3D();
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4
Ruby: Reindeer
Reindeer takes Ruby's existing OO features and extends them with some sugar borrowed from Moose.