Uninitialized constant Layout::Document in ruby api

Hi I starting to use Layout API. I’ve got some trouble at the start

uninitialized constant Adebeo::Customer::Layout::Document

module Adebeo::Customer
class Drawing

	def initialize()

		bom = Adebeo::Customer::Bom.new
		annotations = bom.get_annotations

		@doc = Layout::Document.open("/Users/denisbolomier/Desktop/zertzert\ émail\ /zertzert\ émail\ .layout")

I don’t understand why.
When I’m copying and pasting this code inside the ruby console its working. Why Layout::Document is not reconize inside my class?

Thanks !

You only gave us partial code.
In the very top of the RB file did you include
# encoding: UTF-8
to force the encoding correctly ?
I see your path includes accented characters = émail

1 Like

Thanks TIG, its works!

I code hundred of ruby file and I never have this trouble before. Is it link to Layout ?

You should always include that top line in your RB files.
It stops you accidentally using non-UTF-8 encoded strings in your code.

But if you are getting those strings brought in from ‘outside’ it’s also good practice to force the encoding of those strings to suit Ruby… e.g.

my_file_path = __FILE__.force_encoding("UTF-8")

Just in case perhaps the user’s AppData path is not initially encoding as you need…

NO. It is a Ruby coding paradigm. Denis, please read …

Within module nesting, you can also use the Ruby scope operator to signify top level. Simply precede the module or class identifier with a :: to tell Ruby it is defined in the top level ObejctSpace. …

@doc = ::Layout::Document.open(
  "/Users/denisbolomier/Desktop/zertzert\ émail\ /zertzert\ émail\ .layout"
1 Like

This example also nicely shows the analogy between the leading slash for global paths and leading :: for constant lookup.