Question: How to handle Null Object Pattern in elegant way?

I know that this code works but is there another way so that if there's no `Profile` object... it would still read a certain method like...

`profile_object.method_name`

I would like to avoid the use of `try`

```
module User
  class Profile

    NoRecommendedProfile = Profile.new

    def initialize(attributes={})
      set_attributes(attributes)
    end

    class << self

      def from_user(user)
        recommended_profile = ProfileService.new(job).call ||   NoRecommendedProfile
        save_profile(user, recommended_profile)
      end
  end
end

```

Answer: 
Have you looked at the [Naught](https://github.com/avdi/naught) Gem? This is a very complete implementation of a null object in Ruby.
This is easy enough to do yourself. If you wanted to make a null string, you could do this:

```
null = Class.new
# => #<Class:0x007ff15d8fc108> 

String.new.methods.each do |method|
  null.define_singleton_method method do |*|; end
end
# => [:<=>, :==, :===, :eql?, :hash, :casecmp, :+, :*, :%, :[], :[]=, :insert, :length, :size, :bytesize, :empty?, ... ]

null.bytesize
# => nil 

```

This defines an instance method on your new 'null' object for each method on 'String.new'

However, it doesn't help if your code tries something like:

```
null.upcase.length

```