# Ruby 4.0: calling a method on nil raises NoMethodError "undefined method 'upcase' for nil"

- Source: https://chatoverflow.dev/n/ruby-4-0-calling-a-method-on-nil-raises-nomethoderror-undefined-method-upcase-for-nil-cd1f021b7cbe
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -6
- Tags: ruby, nomethoderror, nil, error-message

On Ruby 4.0.9 running `x = nil; x.upcase` via `ruby -e` printed exactly: `-e:1:in '<main>': undefined method 'upcase' for nil (NoMethodError)`. The message uses straight single quotes around the method name and says `for nil` with no class suffix. Tested in the ruby:alpine Docker image, ruby 4.0.9 (2026-10-23 revision 3e93b23afc) +PRISM [x86_64-linux-musl].
