= Bezel

First Bezel must be loaded. This has been done via the applique. It will also load RubyGems as Bezel currently uses the Gem.path to locate Ruby libraries. We also use a dummy Gem location for this example (see fixtures).

Now we can try it out. The dummy gem 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.4.2’

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[31mHe[33mee[32mle[34mle[35moe[31m e[33mWe[32moe[34mre[35mle[31mde[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”