⚲
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Ruby master
All Projects
Ruby
»
Ruby master
Overview
Activity
Roadmap
Issues
Repository
Like
Download (1.2 KB)
Bug #15849
ยป ruby_named_param_bug.rb
Script demonstrating the issue -
jsmartt (Jared Smartt)
, 05/14/2019 06:37 PM
data
=
{}
# This method does not modify the data hash as expected
def
add_to_broken
(
data
=
{},
key:
'a'
)
data
[
key
]
=
'value'
end
add_to_broken
(
data
)
puts
data
# Trying this fails with an `unknown keyword: b` error
data
=
{
b:
'val'
}
begin
add_to_broken
(
data
)
puts
data
rescue
StandardError
=>
e
puts
"ERROR:
#{
e
}
"
end
# However, the following work as expected:
data
=
{}
# This method successfully modifies the data hash
def
add_to_ok
(
data
,
key
=
'a'
)
data
[
key
]
=
'value'
end
add_to_ok
(
data
)
puts
data
data
=
{}
# This method successfully modifies the data hash
def
add_to_ok2
(
data
)
data
[
'a'
]
=
'value'
end
add_to_ok2
(
data
)
puts
data
data
=
{}
# This method successfully modifies the data hash
def
add_to_ok3
(
data
=
{})
data
[
'a'
]
=
'value'
end
add_to_ok3
(
data
)
puts
data
data
=
{}
# This method does not modify the data hash as expected
def
add_to_ok4
(
data:
{})
data
[
'a'
]
=
'value'
end
add_to_ok4
(
data:
data
)
puts
data
data
=
{}
# This method successfully modifies the data hash
def
add_to_ok5
(
data
:)
data
[
'a'
]
=
'value'
end
add_to_ok5
(
data:
data
)
puts
data
data
=
{}
# This method successfully modifies the data hash
def
add_to_ok6
(
data
,
key:
'a'
)
data
[
key
]
=
'value'
end
add_to_ok6
(
data
)
puts
data
(1-1/1)
Loading...