From: Josh Cheek Date: 2013-04-04T10:22:48+09:00 Subject: Re: Eigenclass: why this syntax? --90e6ba10a96dcf461104d97eceb8 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Apr 3, 2013 at 7:36 PM, Marc Heiler wrote: > - Also, in the above example, is it possible to query the @use_colours > variable for when instance methods of module Foo are mixed into a class? > I would like to mixin instance variables that are defined on the > instance level of the module, inside methods defined in that module. So > yeah, basically I want to use a module like a class, but it seems ruby > gives obstacles to that attempt. > > Not sure I understand the question, but it sounds like you want this: module A attr_accessor :whatev end # include it in the singleton class class B class << self include A end self.whatev = 'something' whatev # => "something" end # shorthand version of the above class C extend A self.whatev = 'something' whatev # => "something" end --90e6ba10a96dcf461104d97eceb8 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Wed, Apr 3, 2013 at 7:36 PM, Marc Heiler <lists@ruby-forum.com= > wrote:
- Also, in the above example, is it possible to query the @use_colours
variable for when instance methods of module Foo are mixed into a class? I would like to mixin instance variables that are defined on the
instance level of the module, inside methods defined in that module. So
yeah, basically I want to use a module like a class, but it seems ruby
gives obstacles to that attempt.


Not sure I understand the question, but it sounds li= ke you want this:

module A
=A0 attr= _accessor :whatev
end

# include it in the singleton class
=
class B
=A0 class << self
=A0 =A0 include A<= /div>
=A0 end
=A0 self.whatev =3D 'something'
=A0 whatev # =3D> "something"
end

# shorthand version of the above
class C
=A0 extend A
=A0 self.whatev =3D 'somethi= ng'
=A0 whatev # =3D> "something"
end<= /div>

--90e6ba10a96dcf461104d97eceb8--