pazdera / word_wrap

A simple word-wrapping tool and a tiny single-purpose library written in Ruby.
MIT License
20 stars 4 forks source link

fails to extend String class #9

Open aspiers opened 6 years ago

aspiers commented 6 years ago

Same issue on Ruby 2.4.1 and 2.2.1. Looks like some module namespacing issue.

$ bundle exec irb
2.4.1 :001 > require 'word_wrap/core_ext'
 => true
2.4.1 :002 > "laksjdf laksdflkasdf".wrap
NameError: uninitialized constant String::WordWrap
        from /home/adam/.rvm/gems/ruby-2.4.1/gems/word_wrap-1.0.0/lib/word_wrap/core_ext.rb:11:in `wrap'
        from (irb):2
        from /home/adam/.rvm/rubies/ruby-2.4.1/bin/irb:11:in `<top (required)>'
        from /home/adam/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/cli/exec.rb:75:in `load'
        from /home/adam/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/cli/exec.rb:75:in `kernel_load'
        from /home/adam/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/cli/exec.rb:28:in `run'
        from /home/adam/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/cli.rb:424:in `exec'
        from /home/adam/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
        from /home/adam/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
        from /home/adam/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
        from /home/adam/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/cli.rb:27:in `dispatch'
        from /home/adam/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
        from /home/adam/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/cli.rb:18:in `start'
        from /home/adam/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/exe/bundle:30:in `block in <top (required)>'
        from /home/adam/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/friendly_errors.rb:122:in `with_friendly_errors'
        from /home/adam/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/exe/bundle:22:in `<top (required)>'
        from /home/adam/.rvm/gems/ruby-2.4.1/bin/bundle:23:in `load'
        from /home/adam/.rvm/gems/ruby-2.4.1/bin/bundle:23:in `<main>'
        from /home/adam/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `eval'
        from /home/adam/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `<main>'
aspiers commented 6 years ago

Ahh I see, you have to require 'word_wrap' first. I'd argue that's a usability bug ;-)

erikw commented 2 years ago

To summarize, both requires are needed. This works:

irb(main):001:0> require "word_wrap"
=> true
irb(main):002:0> require "word_wrap/core_ext"
=> true
irb(main):003:0> "123 456 789".wrap 5
=> "123\n456\n789\n"

@aspiers I think this issue can be closed