fork download
  1. allMask = "*"
  2. class String
  3. define_method(:pathParts) {
  4. ret = self.split(/[\\\/]/, -1)
  5. if(ret.size > 0 && ret[ret.size - 1] == allMask)
  6. ret[0 ... ret.size - 1]
  7. else
  8. ret
  9. end
  10. }
  11. end
  12. p "a/b/c".pathParts
Runtime error #stdin #stdout #stderr 0.02s 7408KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.rb:5:in `block in <class:String>': undefined local variable or method `allMask' for "a/b/c":String (NameError)
	from prog.rb:12:in `<main>'