Created
July 30, 2012 11:49
-
-
Save edtsech/3206400 to your computer and use it in GitHub Desktop.
Two classes with the same name, but with different obejct_id.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ContentFor = Class.new | |
x = ContentFor.new | |
puts x.class.object_id # => 2266662780 | |
# puts x.class.name | |
ContentFor = Class.new | |
y = ContentFor.new | |
puts x.class.object_id # => 2266662780 | |
puts x.class.name # => nil | |
puts y.class.object_id # => 2266662700 | |
puts y.class.name # => nil | |
puts ContentFor.object_id # => 2266662700 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ContentFor = Class.new | |
x = ContentFor.new | |
puts x.class.object_id # => 2266662780 | |
puts x.class.name # => ContentFor | |
ContentFor = Class.new | |
y = ContentFor.new | |
puts x.class.object_id # => 2266662780 | |
puts x.class.name # => ContentFor | |
puts y.class.object_id # => 2266662700 | |
puts y.class.name # => ContentFor | |
puts ContentFor.object_id # => 2266662700 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ContentFor < Liquid::Tag | |
... | |
end | |
..... | |
node.class # => ContentFor | |
node.class.object_id # => 70174154320900 | |
ContentFor.object_id # => 70174175475880 | |
node.is_a? ContentFor # => false | |
node.class.name == "ContentFor" # => true | |
Ну достижимые знают свое имя по очевидной причине :)
Я не вижу разницы в двух примерах, и я скопипастил первый пример, и там у меня пишется имя для обоих классов. Может быть показалось, там puts стоит - в консоли он сначала выводит то, что в него передали, а потом nil
Вот мой вывод:
➜ ~ ruby boom.rb
70320438645840
boom.rb:7: warning: already initialized constant ContentFor
70320438645840
70320438645740
ContentFor
70320438645740
➜ ~ ruby boom2.rb
70305804877520
ContentFor
boom2.rb:7: warning: already initialized constant ContentFor
70305804877520
ContentFor
70305804877380
ContentFor
70305804877380
@Mik-die я просто думал имя как-то зависит от достижимости, раз ты акцентировал внимание на том, что недостижимые помнят имя. Но не суть, теперь понял.
Да, вижу, в консоли это не было заметно..
http://codepad.org/gGZzowA9
http://codepad.org/vYznrZoO
Наверное имя как-то лениво определяется.. там си, не хочу смотреть :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Mik-die что можешь сказать кстати по поводу разницы между boom.rb и boom2.rb ? Я незнаю почему в одном случае сохраняется имя в другом нет.