Let's start by saying that what you show as a function in first example is a method.
In Ruby everything is an object. So if you define some method just like in your first example, it still belongs to some object.
irb(main):001:0> self
=> main
irb(main):002:0> self.class
=> Object
You see, even if you just call irb, the context you execute code is an instance of Object class.
So what you actually want is a method which is available globally in scope of Rails application. You can achieve it by including some module right in your application (like in other answers to this question)
However, I suggest different way. Instead of creating a global method, create a class/module with that method. Classes and modules are globally accessible, so you will be able to use it everywhere (see fivedigit's answer for example).
App::debug($var)available in all your scope via autoloader