Skip to content

Commit 87c063b

Browse files
committed
Data#initialize supports String keywords
1 parent 0edc91b commit 87c063b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

spec/ruby/core/data/initialize_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
data.unit.should == "km"
3232
end
3333

34+
it "accepts String keyword arguments" do
35+
data = DataSpecs::Measure.new("amount" => 42, "unit" => "km")
36+
37+
data.amount.should == 42
38+
data.unit.should == "km"
39+
end
40+
3441
it "raises ArgumentError if no arguments are given" do
3542
-> {
3643
DataSpecs::Measure.new

src/main/ruby/truffleruby/core/data.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,13 @@ def self.new(*args, **kwargs)
8484
# CRuby defines these directly on Data, but that is suboptimal for performance.
8585
# We want to have a specialized copy of these methods for each Data subclass.
8686
instance_methods_module = Module.new
87-
instance_methods_module.module_eval "#{<<~'RUBY'}"
87+
instance_methods_module.module_eval "#{<<~'RUBY'}", __FILE__, __LINE__+1
8888
# truffleruby_primitives: true
8989
9090
def initialize(**kwargs)
9191
members_hash = Primitive.class(self)::CLASS_MEMBERS_HASH
9292
kwargs.each do |member, value|
93+
member = member.to_sym
9394
if members_hash.include?(member)
9495
Primitive.object_hidden_var_set(self, member, value)
9596
else

0 commit comments

Comments
 (0)