Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Foundations Procs & Lambdas Working With Procs & Lambdas

I think I copied the code exactly.. why am I getting nil instead of Title, Heading, and Body

 class Paper
    def intialize(&block)
        yield self if block_given?
    end

    def set_variable
        return Proc.new do |kind, val|
            [kind, val].join(": ")
        end
    end

    def title(value)
        @title = set_variable.call "TITLE", value
    end

    def heading(value)
        @heading = set_variable.call "HEADING", value
    end

    def body(value) 
        @body = set_variable.call "BODY", value
    end
    def display
        puts @title
        puts "------------------"
        puts @heading
        puts "------------------"
        puts @body
        puts "------------------"
    end
end

paper = Paper.new do |p|
    p.title "my awesome paper"
    p.heading "this is my paper"
    p.body "the entire contents of my paper would go here"
end

paper.display 

1 Answer

Ilya Dolgirev
Ilya Dolgirev
35,375 Points

Hi! You just have a typo:

def intialize(&block)

Change it to:

def initialize(&block)