Skip to content

No, I actually hate instance_eval, but it can be done better #5

@czaks

Description

@czaks

How about supporting a theoretical code like this?

class Page
  include Paggio::HTML

  def initialize(title, content)
    @title   = title
    @content = content
  end

  def to_html
    html do
      head do
        title @title
      end

      body do
        @content
      end
    end
  end
end

puts Page.new("foo", "bar").to_html

What I done here, is include a mixin, which moves all HTML tag methods into the class context. Sure, we would need to be extra careful not to override those. This way, it would encourage object-oriented programming with no problems related to instance_eval use.

This is how https://github.com/erector/erector works, afaik.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions