I use FXRuby gem for writing Ruby GUI, but I can’t configure the encoding for Cyrillic recognition, I know that this is done through the font setting, but all this is not displayed

app = FXApp.new ffont = FXFont.new(app,"helvetica,110,unicode") main = FXMainWindow.new(app,"Memory", :width=>1200, :height=>200 ) ftext = FXLabel.new(main,"") ftext.font = ffont ftext.text = [@Memories[0].getEvent,' ',@Memories[0].getDay,' ',@Memories[0].getMonth,' ',@Memories[0].getName].to_s app.create main.show(PLACEMENT_SCREEN) app.run 

Result

  • And if so? ftext.text = [@Memories[0].getEvent, @Memories[0].getDay, @Memories[0].getMonth, @Memories[0].getName].join(" ") ` - Nakilon
  • one
    Thanks, everything works, can you explain why it did not work in the first case, and it worked in the second? - Lukashman
  • Issued a Answer. - Nakilon

1 answer 1

Apparently, Array#to_s with objects inside the array works like .inspect - I do not have Ruby on hand to express myself more precisely. But when the inspect method is called on strings with cunning characters, you see their hexadecimal representation there, as in the screenshot.

 ftext.text = [@Memories[0].getEvent, @Memories[0].getDay, @Memories[0].getMonth, @Memories[0].getName].join(" ") 

The same code variant does not call Array#to_s , but turns an array into a string by another method and then gives it to the GUI library, which, as it follows from this, was not to blame for your problem.

UPD: yes, it is written that to_s in the case of Array inspect alias: https://ruby-doc.org/core-2.2.0/Array.html#method-i-to_s