[Ruby] undefined method `dark?'occurs in rqr_code

Task

When I used rqr_code with reference to the existing article, the undefined method `dark?'Was displayed.

Reproduction procedure

rqr_code installation


$ gem install rqrcode_png

Full copy of basic code


require 'rqrcode'
require 'rqrcode_png'
require 'chunky_png'

qr = RQRCode::QRCode.new( "Hello World!!", size: 3, level: :h)
img = qr.to_img

img.resize(200, 200).save("hello_world.png ")

Execution error


$ ruby qr_code.rb 
Traceback (most recent call last):
<Omission>
rqrcode_png/sequence.rb:11:in `block (2 levels) in dark_squares_only': undefined method `dark?' for #<RQRCode::QRCode:0x00007f9126021200> (NoMethodError)

Conclusion

I was able to avoid it with .as_png instead of .to_img.

ruby:.to_img.as_Change to png


require 'rqrcode'
require 'rqrcode_png'
require 'chunky_png'

qr = RQRCode::QRCode.new( "Hello World!!", size: 3, level: :h)
# img = qr.to_img
img = qr.as_png

img.resize(200, 200).save("hello_world.png ")

Reference information

[Ruby] QR code generation and embedding https://qiita.com/koteko/items/d6d033997c544c47b718

How to easily generate a QR code image in Ruby https://qiita.com/sakaitaka/items/c753103c93fa177e4466

rqrcode https://github.com/whomwah/rqrcode

Recommended Posts

[Ruby] undefined method `dark?'occurs in rqr_code
String output method memo in Ruby
Implemented "Floyd Cycle Detection Method" in Ruby
Ruby to_s method
[Ruby] slice method
[Ruby] end_with? method
[Ruby] Method memorandum
Heavy in Ruby! ??
[Ruby] initialize method
Ruby build method
Ruby accessor method
ruby map method
[Ruby on Rails] NoMethodError undefined method `devise_for'error resolution
About regular expressions used in ruby sub method
When I run minitest in vscode's Ruby Test Explorer, NoMethodError: undefined method `klass'for ...
Ruby Learning # 30 Initialize Method
abbreviation for ruby method
About eval in Ruby
Examine the elements in the array using the [Ruby] includes? Method
Ruby Learning # 24 Exponent Method
Ruby Thread # [] = method notes
I got an error "undefined method` create'" in RSpec
[For beginners] ○○. △△ in Ruby (ActiveRecord method, instance method, data acquisition)
[Ruby] Method definition summary
Fast popcount in Ruby
[Ruby] Count an even number in an array using the even? Method
[Ruby on Rails] undefined method ʻid'for nil: NilClass error resolution method
In Ruby you can define a method with any name
ABC177 --solving E in Ruby
Validate JWT token in Ruby
Implemented XPath 1.0 parser in Ruby
Read design patterns in Ruby
Write class inheritance in Ruby
Code entry method in Qiita
Integer check method with ruby
Integer unified into Integer in Ruby 2.4
Multiplication in a Ruby array
About regular expressions in Ruby
Basic knowledge in method definition
Birthday attack calculation in Ruby
[Ruby] Notes on gets method
Judgment of fractions in Ruby
Find Roman numerals in Ruby
Try using gRPC in Ruby
[Ruby] Method that returns truth
When using Slim in Ruby on Rails, "undefined local variable or method` f'for "is displayed in form_with
[Ruby] Find numbers in arrays
[ruby] Method call with argument
NCk mod p in Ruby
Chinese Remainder Theorem in Ruby
Undefined local variable or method error in partial template collection option