Skip to content

Instantly share code, notes, and snippets.

@mvidner
Last active December 22, 2015 09:19
Show Gist options
  • Select an option

  • Save mvidner/6451197 to your computer and use it in GitHub Desktop.

Select an option

Save mvidner/6451197 to your computer and use it in GitHub Desktop.
Ruby: .method vs ::constant
mvidner@mrakoplas:~$ irb
irb(main):001:0> require 'yast'
<internal:prelude>:18: warning: already initialized constant MUTEX_FOR_THREAD_EXCLUSIVE
=> true
irb(main):003:0> Yast.import "Label"
=> nil
irb(main):006:0> Yast::Label.AddButton
=> "&Add"
irb(main):007:0> Yast::Label::AddButton
TypeError: #<Yast::LabelClass:0x00000002742000 @my_textdomain="base"> is not a class/module
from (irb):7
from /usr/bin/irb:12:in '<main>'
irb(main):008:0> Yast::BACKTRACE_REGEXP
=> /^(.*):(\d+):in `.*'$/
irb(main):009:0> Yast.BACKTRACE_REGEXP
NoMethodError: undefined method 'BACKTRACE_REGEXP' for Yast:Module
from (irb):9
from /usr/bin/irb:12:in '<main>'
@jreidinger

Copy link
Copy Markdown

That is exactly what I write in my comment. So probably just misunderstanding.

[reformatted] But you are right that in this case it doesn't happen, because there is LanItems.GetCurrentName and for constant it must be LanItems::GetCurrentName . but if it stand alone, there must be () or use ruby convention 😉

@mvidner

mvidner commented Sep 6, 2013

Copy link
Copy Markdown
Author

Ah, I indeed misunderstood. BTW, while here we distinguish between constants and methods, I have another snippet that compares constants to variables: https://gist.github.com/mvidner/4002448

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment