# What does undefined local variable or method mean in Ruby?

Source: https://poignantguide.net/answers/read/what-does-undefined-local-variable-or-method-mean-in-ruby/
Site: Poignant Guide Ruby Q&A, category Errors and debugging help
Published: 2026-12-02. Updated: 2026-12-02. Replies: 2.

## Question by Pablo M., 2026-12-02

ok so im doing the little greeting program from my school Ruby project and it crashes and i dont get the error. the variable is RIGHT THERE

```ruby
def greet
  puts "Hi #{name}"
end

name = "Pablo"
greet
```

```
greeter.rb:2:in `greet': undefined local variable or method `name' for main:Object (NameError)
```

Ruby 3.3, running it with `ruby greeter.rb`. I typed `name` correctly, I checked 3 times. I also tried moving `name = "Pablo"` above the `def` and it still crashes. chatgpt said it was a "scope issue" but didnt really explain what that means and i dont want to just copy the fix.

what does "undefined local variable or method" mean, is it a variable or a method?? and how do i find out what went wrong when i see this error next time

## Reply 1 by Junko T., 2026-12-02

The message says "variable or method" because Ruby really does not know which one you meant. A bare word like `name` could be a local variable or a call to a method named `name`, and Ruby looked for both and found neither. That ambiguity is in the wording on purpose.

## Reply 2 by Kai N., 2026-12-02

Make it a global: `$name = "Pablo"` and use `$name` inside greet. Works everywhere, and it is the fastest way to get the program running before the deadline. I do it in all my small scripts.

---
Cite as: Poignant Guide Ruby Q&A, "What does undefined local variable or method mean in Ruby?", https://poignantguide.net/answers/read/what-does-undefined-local-variable-or-method-mean-in-ruby/, accessed 2026-12-04.
