Create a class dynamically
material = 'cotton'
class << material
def definition
puts 'this is a test.'
end
end
puts material.definition
'cotton'.definition
# NoMethodError: undefined method 'definition' for "cotton":String
material.clone.definition
material.dup.definition
# NoMethodError: undefined method 'definition' for "cotton":String
Related examples in the same category