Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Gem::Specification#ruby_code
ruby_code(obj)
lib/rubygems/specification.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/lib/rubygems/specification.rb, line 2364
def ruby_code(obj)
case obj
when String then obj.dump + ".freeze"
when Array then "[" + obj.map {|x| ruby_code x }.join(", ") + "]"
when Hash then
seg = obj.keys.sort.map {|k| "#{k.to_s.dump} => #{obj[k].to_s.dump}" }
"{ #{seg.join(", ")} }"
when Gem::Version then ruby_code(obj.to_s)
when DateLike then obj.strftime("%Y-%m-%d").dump
when Time then obj.strftime("%Y-%m-%d").dump
when Numeric then obj.inspect
when true, false, nil then obj.inspect
when Gem::Platform then "Gem::Platform.new(#{ruby_code obj.to_a})"
when Gem::Requirement then
list = obj.as_list
"Gem::Requirement.new(#{ruby_code(list.size == 1 ? obj.to_s : list)})"
else raise Gem::Exception, "ruby_code case not handled: #{obj.class}"
end
end
Return a string containing a Ruby code representation of the given object.
See also
#ri_dir
#runtime_dependencies
#reset_nil_attributes_to_default
#same_attributes?
also in
4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0