• Publicidad

Algo tiene Moose... cuando se le imita

¿Tienes algo interesante que decir? ¿O quizá algo no tan interesante? Aquí tenemos un espacio para compartir todo lo que queramos decir y que no cabe en ninguno de los otros foros.

Algo tiene Moose... cuando se le imita

Notapor explorer » 2015-06-14 06:56 @330

Python: Elk
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
Sintáxis: [ Descargar ] [ Ocultar ]
Using python Syntax Highlighting
  1. import elk
  2.  
  3.  
  4. class Point(elk.Elk):
  5.     x = elk.ElkAttribute(mode='rw', type=int)
  6.     y = elk.ElkAttribute(mode='rw', type=int)
  7.  
  8.     def clear(self):
  9.         self.x = 0
  10.         self.y = 0
  11.  
  12.  
  13. class Point3D(Point):
  14.     z = elk.ElkAttribute(mode='rw', type=int)
  15.  
  16.     @elk.after('clear')
  17.     def clear_z(self):
  18.         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
Sintáxis: [ Descargar ] [ Ocultar ]
Using ruby Syntax Highlighting
  1. require 'moosex'
  2.  
  3. class Point
  4.   include MooseX
  5.  
  6.   has x: {
  7.     is: :rw,      # read-write (mandatory)
  8.     isa: Integer, # should be Integer
  9.     default: 0,   # default value is 0 (constant)
  10.   }
  11.  
  12.   has y: {
  13.     is: :rw,
  14.     isa: Integer,
  15.     default: -> { 0 }, # you should specify a lambda
  16.   }
  17.  
  18.   def clear!
  19.     self.x= 0     # to run with type-check you must
  20.     self.y= 0     # use the setter instad @x=
  21.   end
  22.  
  23.   def to_s
  24.     "Point[x=#{self.x}, y=#{self.y}]"
  25.   end
  26. end
  27.  
  28. # now you have a generic constructor
  29. p1  = Point.new                       # x and y will be 0
  30. p2  = Point.new( x:  5 )              # y will be 0
  31. p3  = Point.new( x:  5, y: 4)
Coloreado en 0.004 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.
Sintáxis: [ Descargar ] [ Ocultar ]
Using javascript Syntax Highlighting
  1. var Person = new o.Class({
  2.     attributes: {
  3.         name: { type:o.nonEmptyStringType },
  4.         age: { type:o.integerType }
  5.     },
  6.     methods: {
  7.         log_name: function () {
  8.             console.log( this.name() );
  9.         }
  10.     }
  11. });
  12. var baggins = new Person({
  13.     name: 'Bilbo',
  14.     age: 111
  15. });
  16. 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.
Sintáxis: [ Descargar ] [ Ocultar ]
Using javascript Syntax Highlighting
  1. Class("Point", {
  2.     has: {
  3.         x: {is: "ro"},
  4.         y: {is: "rw"},
  5.     },
  6.     methods: {
  7.         clear: function () {
  8.             this.x = 0;
  9.             this.setY(0);
  10.         }
  11.     }
  12. })
  13.  
  14. Class("Point3D", {
  15.     isa: Point,
  16.     has: {
  17.         z: {}
  18.     },
  19.     after: {
  20.         clear: function () {
  21.             this.z = 0;
  22.         }
  23.     }
  24. })
  25.  
  26. var point = new Point3D();
Coloreado en 0.001 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.
Sintáxis: [ Descargar ] [ Ocultar ]
Using ruby Syntax Highlighting
  1. require 'reindeer'
  2. class Point < Reindeer
  3.   has :x, is: :rw, is_a: Integer
  4.   has :y, is: :rw, is_a: Integer
  5. end
  6. class Point3D < Point
  7.   has :z, is: :rw, is_a: Integer
  8. end
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Publicidad

Volver a Pasando el rato

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 3 invitados