Bezel

First Bezel must be loaded, of course. We have already done this via the applique. This will also load RubyGems as Bezel presently uses the Gem.path to locate Ruby libraries. We are use a dummy Gem location for this example (see fixtures).

Now we can try it out. The dummy location houses two libraries of the same name but different versions.

module Example1
  TryMe = lib('tryme', '1.0')
end

TryMe has a class method called #report and we should see that it works as expected.

Example1::TryMe.report.assert == "You are using version 1.0!"

It also imports a method called #extra from a seperate file.

Example1::TryMe.extra.assert == "Something extra from version 1.0!"

Now we should be able to do the same for TryMe v1.1 without any issues of interference between the two versions.

module Example2
  TryMe = lib('tryme', '1.1')
end

Again we should see that the #report method works as expected, but this time reported form the new version.

Example2::TryMe.report.assert == "You are using version 1.1!"

And that it also imports a method called #extra from a seperate file.

Example2::TryMe.extra.assert == "Something extra from version 1.1!"

Just to be sure, let try v1.0 again.

Example1::TryMe.report.assert == "You are using version 1.0!"
Example1::TryMe.extra.assert == "Something extra from version 1.0!"

That’s all folks!

ANSI Example

require 'bezel'

ANSI_VERSION = '1.2.6'

class ColorfulString
  X = lib('ansi', ANSI_VERSION)
  #include x

  COLORS = [:red, :yellow, :green, :blue, :magenta]

  def initialize(string)
    @string = string
    reset_colors
  end

  def to_s
    s = ""
    @string.split(//).each do |c|
      s << X::ANSI::Code.send(next_color) + c;
    end
    s << X::ANSI::Code::CLEAR
    reset_colors
    return s
  end

  def next_color
    color = @colors.shift
    @colors << color
    color
  end

  def reset_colors
    @colors = COLORS.dup
  end
end

Then

cs = ColorfulString.new("Hello World!")

#puts cs

cs.to_s.assert == "\e[31mH\e[33me\e[32ml\e[34ml\e[35mo\e[31m \e[33mW\e[32mo\e[34mr\e[35ml\e[31md\e[33m!\e[0m"

ANSI 1.2.6+ has been fine-tuned to work with Bezel. So even core extensions work.

red = "How about this!".ansi(:red)

red.assert == "\e[31mHow about this!\e[0m"