From: Nikolay Pavlov Date: 2007-11-02T02:39:13+09:00 Subject: Re: How to extend class with the particular method --nextPart12066453.aGlo0FP0Zf Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Thursday 01 November 2007 17:47:06 Robert Dober wrote: > Hmm I am not 100% sure what you want exactly > if I understand correctly you want to include a single method of a > module into whatever. > I have implemented this in traits but the overhead is big, you can > however see in the code > how this is done. > Maybe it is worthy to look into the "use" package, written by Daniel. > It does *exactly* and *only* that.This has been discussed in the > original announcement of the traits > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/274261 That was extremely helpfull. Thanks :) irb(main):032:0> require 'use' =3D> true irb(main):033:0> module Operational irb(main):034:1> irb(main):035:1* def self.included(base) irb(main):036:2> base.extend ClassMethods irb(main):037:2> end irb(main):038:1> irb(main):039:1* module ClassMethods irb(main):040:2> def operational_as(method_name, options =3D {}) irb(main):041:3> self.instance_eval do irb(main):042:4* use Behavior, method_name irb(main):043:4> end irb(main):044:3> end irb(main):045:2> end irb(main):046:1> module Behavior irb(main):047:2> def bob irb(main):048:3> end irb(main):049:2> def sam irb(main):050:3> end irb(main):051:2> end irb(main):052:1> end =3D> nil irb(main):053:0> class Op irb(main):054:1> include Operational irb(main):055:1> end =3D> Op irb(main):058:0> @phantomas =3D Op.new =3D> # irb(main):056:0> Op.operational_as(:bob) =3D> Op irb(main):060:0> @phantomas.respond_to?(:bob) =3D> true irb(main):061:0> @phantomas.respond_to?(:sam) =3D> false irb(main):062:0> Op.operational_as(:sam) =3D> Op irb(main):063:0> @phantomas.respond_to?(:bob) =3D> false irb(main):064:0> @phantomas.respond_to?(:sam) =3D> true =2D-=20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 =2D Best regards, Nikolay Pavlov. <<<----------------------------------- = =20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 --nextPart12066453.aGlo0FP0Zf Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQBHKg6E/2R6KvEYGaIRAuZyAKDDAYaLy9P6jE8HK/0oHCA8mFiyuQCeKWEo 1WGMZrw4jv4BwgeMPjjDXFM= =FbtJ -----END PGP SIGNATURE----- --nextPart12066453.aGlo0FP0Zf--