Forum: Ruby what does :: do in this case?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
petermichaux (Guest)
on 2005-11-21 00:04
(Received via mailing list)
Hi

This is in the Rails acts_as_list module but I think is a general Ruby
question. I don't understand the syntax of the ::#{self.name}
statement. I haven't seen :: without something preceding it. I think I
understand what this method enables the plugin to do: use the class
name in which the module is mixed.

Thanks,
Peter



module ActiveRecord
  module Acts
    module List

      def acts_as_list_class
        ::#{self.name}
      end

    end
  end
end
halostatue (Guest)
on 2005-11-21 00:12
(Received via mailing list)
On 11/20/05, removed_email_address@domain.invalid 
<removed_email_address@domain.invalid> wrote:
> This is in the Rails acts_as_list module but I think is a general Ruby
> question. I don't understand the syntax of the ::#{self.name}
> statement. I haven't seen :: without something preceding it. I think I
> understand what this method enables the plugin to do: use the class
> name in which the module is mixed.

Unless that's in a section of string code to be evaled, that's
actually a syntax error. (The #{} syntax is only valid in strings).

However, if you do:

  ::File

You mean specifically that you want the File constant visible at the top
level.

-austin
This topic is locked and can not be replied to.