Explain where the error is?
I create a component (a simple cube)
And set attribute Name = test
Save the file as test.skp and close Sketchup.
Open the Sketchup file test.skp and enter in the Ruby Console code :
model = Sketchup.active_model
entity = model.selection[0]
puts entity.get_attribute("dynamic_attributes","name","").to_s
get the name of the component test. (image1)

So far everything is fine.
Next, I save a component from the context menu "Save As"
Open a new file and load component cub from the menu Components
Again enter in the Ruby Console the same code
And get nothing. (image2)

Why when loading a component of their menu Components
code does not work ?
however , the code :
Sketchup.active_model.selection[0].definition.attribute_dictionary('dynamic_attributes').each_pair { |k,v| puts k + '; ' + v.to_s }
correctly displays the name attribute of the component (among other attributes)

In the General case I need the code displays the name attribute of the component.