Skip to content

Instantly share code, notes, and snippets.

@sharmaabhinav
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save sharmaabhinav/071cb1d20492c5005e6f to your computer and use it in GitHub Desktop.

Select an option

Save sharmaabhinav/071cb1d20492c5005e6f to your computer and use it in GitHub Desktop.
class OperatorDemo
attr_accessor :name
def initialize(params = {})
self.name = params.fetch(:name, "abhinav")
end
def +(name2)
params = { name: name + " " + name2.name }
obj = create_obj(params)
return obj
end
def create_obj(params)
OperatorDemo.new(params)
end
def to_s
name
end
end
x = OperatorDemo.new
y = OperatorDemo.new({ name: "sharma" })
z = x + y
puts z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment