Midwest Dev Chat

MidwestDevChat.com

  • The newest 15 messages in the super-cool #ruby channel.

  • 02/10 20:35:22 Argelia: whoops!
  • 02/10 21:09:36 Argelia: i was just highlighting an edge case: hunting for nil and, when thinking about that edge case, it occurred to me that `detect` only returning a single value can fall short so it's the specific situation of *the failure signal value being inside the set of values being looked for*. it's an edge case. it doesn't happen a lot. _but_ though I realize it's mostly a non-issue, it could _always_ be a non-issue if `detect` always returned 2 values value 1) whether the search was successful value 2) the value found i suppose throwing an exception for an event that is reasonable to expect—that _isn't_ exceptional—is a bad idea, but it _does_ do the job of returning 2 values
  • 02/10 22:12:14 Argelia: The obvious solution troll
    class DeterktError < StandardError
    end
    
    class Array
      def deterkt(&block)  
        [true, self.detect(->{raise DeterktError, "Not Found"}, &block)]
      rescue DeterktError => e
        [false, nil]
      end
    end
    
  • 02/11 07:42:23 Argelia: or you could tailor your failure signal value when you need to thinking_face
    [0, ''].detect(->{true}) {|x| !x} # true (failure)
    [0, '', nil, false].detect(->{true}) {|x| !x} # nil (falsey value found)
    
  • 02/11 07:49:08 Argelia: maybe it isn't that weird
    failure_signal = 'not found'
    result = [.....].detect(->{failure_signal}) {|x| !x}
    return .... if result == failure_signal
    ....
    
  • 02/11 07:50:31 Argelia: ¯\_(ツ)_/¯
  • 02/11 12:56:56 Dulcie: I don't like Go's approach to error handling _at all_ and I'd never want to do that sort of thing in Ruby
  • 02/11 12:57:37 Dulcie: you're talking about `nil` as an _failure_ here but I would push back on that and say that if you're using `detect`, then `nil` is a perfectly valid result for your use-case.
  • 02/11 15:14:47 Argelia: werd up @Manuela
  • 02/18 09:08:33 Argelia: 1) how is it that `cd`ing into a directory prompted that message. (edited) (changing directory triggered some other event, bah???) 2) looks like I _do_ have that version.
  • 02/18 09:15:01 Chantell: what do you have if you run `rvm list` ?
  • 02/18 09:16:20 Chantell: `rvm` has some sort of wrapper around `cd` so that it can check for indications of ruby versions and gemsets when you move directories and switch to the correct setup
  • 02/18 09:17:02 Chantell: I wonder if perhaps ruby 2.5.1 wasn't installed via rvm and therefore it's not picking up that version or something?
  • 02/18 09:17:30 Ginger: `which ruby`?
  • *Usernames have been changed to protect the innocent.
We're currently 1136 members strong. Join us!
Request Invite

Check out all the cool channels!

Join the conversation!