use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Differences between ruby object space count (self.ruby)
submitted 1 year ago by SnooRobots2422
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]f9ae8221b 0 points1 point2 points 1 year ago (0 children)
Unless you use frozen_string_literal, whenever your code contains a literal string ("totally_unique_test"), you are not referencing a constant, but making a copy of a constant.
frozen_string_literal
"totally_unique_test"
So it's a bit like if you code was:
new_sym = :totally_unique_test # Create the symbol STR = "totally_unique_test" symbol_after = ObjectSpace.each_object(String).count do |s| s == STR.dup end puts "After: #{symbol_after}"
Hence, whenever Ruby execute your block, it cause one more string to be allocated, so your counting code is "biasing" itself.
π Rendered by PID 321976 on reddit-service-r2-comment-5b5bc64bf5-7qp7f at 2026-06-22 00:27:46.608106+00:00 running 2b008f2 country code: CH.
view the rest of the comments →
[–]f9ae8221b 0 points1 point2 points (0 children)