Created
December 3, 2018 14:27
-
-
Save Bijendra/0b46e17d29420578834096c6e6e83e64 to your computer and use it in GitHub Desktop.
Ruby Meta Blogspot Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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