VS
у конструктора класса в качестве параметра есть некий name, в конструктуре написано @name = name
и нужно выяснить задавался ли при создании экземпляра класса этот параметр, и если да, то является ли он строкой.
я правильно понял?
Size: a a a
VS
S
DK
VS
V
Class
.Class
могут иметь свои собственные экземпляры.instance_of_anonymous_class =
Class.new do
def abc # We can define an instance method of the anonymous class
'abc'
end
end.new
# Let's figure out the class name
instance_of_anonymous_class.class.name # => nil
# We can call instance methods of the anonymous class
instance_of_anonymous_class.abc # => "abc"
# We can create another instance of the same anonymous class
another_instance = instance_of_anonymous_class.class.new
1
Class
.Class
могут иметь свои собственные экземпляры.instance_of_anonymous_class =
Class.new do
def abc # We can define an instance method of the anonymous class
'abc'
end
end.new
# Let's figure out the class name
instance_of_anonymous_class.class.name # => nil
# We can call instance methods of the anonymous class
instance_of_anonymous_class.abc # => "abc"
# We can create another instance of the same anonymous class
another_instance = instance_of_anonymous_class.class.new
1
Class
.Class
могут иметь свои собственные экземпляры.instance_of_anonymous_class =
Class.new do
def abc # We can define an instance method of the anonymous class
'abc'
end
end.new
# Let's figure out the class name
instance_of_anonymous_class.class.name # => nil
# We can call instance methods of the anonymous class
instance_of_anonymous_class.abc # => "abc"
# We can create another instance of the same anonymous class
another_instance = instance_of_anonymous_class.class.new
V
hello_world
.instance_of_anonymous_class
..new
на созданном анонимном классе.1
hello_world
.instance_of_anonymous_class
..new
на созданном анонимном классе.V
hello_world
.hello_world =А теперь немножко изменим код - присвоим ссылку на анонимный класс константе и посмотрим в какой момент анонимный класс перестаёт быть анонимным и получает имя
Class.new do
def say
'hello'
end
end
hello_world.name # => nil
HelloWorld
:HelloWorld =Здесь видно, что если ссылка на класс присваивается константе (начинается с большой буквы), то Ruby сразу после присвоения константе ссылки на анонимный класс сообщает ему его имя
Class.new do
def say
'hello'
end
end.tap { |cl| p cl.name } # => nil
HelloWorld.name # => "HelloWorld"
HelloWorld
.E
hello_world
.hello_world =А теперь немножко изменим код - присвоим ссылку на анонимный класс константе и посмотрим в какой момент анонимный класс перестаёт быть анонимным и получает имя
Class.new do
def say
'hello'
end
end
hello_world.name # => nil
HelloWorld
:HelloWorld =Здесь видно, что если ссылка на класс присваивается константе (начинается с большой буквы), то Ruby сразу после присвоения константе ссылки на анонимный класс сообщает ему его имя
Class.new do
def say
'hello'
end
end.tap { |cl| p cl.name } # => nil
HelloWorld.name # => "HelloWorld"
HelloWorld
.SR
[[117501, "22", "2020-12-10"], [117501, "22", "2020-12-15"], [507, "22", "2020-12-15"]]
{117501=>[["22", "2020-12-15"], ["22", "2020-12-10"]], 507=>["22", "2020-12-15"]}
SR