Skip to content

Instantly share code, notes, and snippets.

@Bijendra
Created December 3, 2018 14:27
Show Gist options
  • Save Bijendra/0b46e17d29420578834096c6e6e83e64 to your computer and use it in GitHub Desktop.
Save Bijendra/0b46e17d29420578834096c6e6e83e64 to your computer and use it in GitHub Desktop.
Ruby Meta Blogspot Example
class Employee
attr_accessor :emp_id, :emp_name, :emp_designation, :emp_department
def assign_attributes(emp_data)
emp_data.each do |k,v|
self.send("#{k}=", v)
end
end
end
emp_data = { emp_id: 1, emp_name: "Employee1", emp_designation: "Level1", emp_department: "Manufacturing"}
emp_obj = Employee.new
emp_obj.assign_attributes(emp_data)
puts emp_obj.inspect
Output:
#<Employee:0x007fb959904768 @emp_id=1, @emp_name="Employee1", @emp_designation="Level1", @emp_department="Manufacturing">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment