Instructions
Create a function create_person that takes a name and age
and returns a hash with :name and :age keys.
Example: create_person("Alice", 30) returns {name: "Alice", age: 30}
Hints:
- Use symbol keys: { name: value, age: value }
- Or use the arrow syntax: { :name => value }
- Both syntaxes work the same way
Your Code
def create_person(name, age)
{ name: name, age: age }
end
RSpec.describe "create_person" do
it "creates a person hash" do
expect(create_person("Alice", 30)).to eq({ name: "Alice", age: 30 })
end
it "works with different values" do
expect(create_person("Bob", 25)).to eq({ name: "Bob", age: 25 })
end
end
Results
Click "Run Tests" to see results
1 / 4
Next: Get Hash Value