What is the easiest way to remove the first character from a string?
Similar to Pablo’s answer above, but a shade cleaner : str[1..-1] Will return the array from 1 to the last character. ‘Hello World'[1..-1] => “ello World”
Similar to Pablo’s answer above, but a shade cleaner : str[1..-1] Will return the array from 1 to the last character. ‘Hello World'[1..-1] => “ello World”
Your Ruby is installed in /usr/local/Cellar/ruby/…. That is a restricted path and can only be written to when you use elevated privileges, either by running as root or by using sudo. I won’t recommend you run things as root since you don’t understand how paths and permissions work. You can use sudo gem install jekyll, … Read more
I ended up installing zlib from apt-get and then reinstalling ruby to not use the rvm directory for zlib. Here’s how do: $ sudo apt-get install zlib1g-dev $ rvm reinstall 1.9.3 [Edit] As commenter @chrisfinne mentions, on CentOS/RedHat based systems: $ sudo yum install zlib-devel $ rvm reinstall 1.9.3
Edit: Since I wrote this answer Base64.strict_encode64() was added, which does not add newlines. The docs are somewhat confusing, the b64encode method is supposed to add a newline for every 60th character, and the example for the encode64 method is actually using the b64encode method. It seems the pack(“m”) method for the Array class used … Read more
Some methods take a block, and this pattern frequently appears for a block: {|x| x.foo} and people would like to write that in a more concise way. In order to do that they use a combination of: a symbol, the method Symbol#to_proc, implicit class casting, and & operator. If you put & in front of … Read more
(0..50).to_a.sort{ rand() – 0.5 }[0..x] (0..50).to_a can be replaced with any array. 0 is “minvalue”, 50 is “max value” x is “how many values i want out” of course, its impossible for x to be permitted to be greater than max-min 🙂 In expansion of how this works (0..5).to_a ==> [0,1,2,3,4,5] [0,1,2,3,4,5].sort{ -1 } ==> … Read more
The <<- form of heredoc only ignores leading whitespace for the end delimiter. With Ruby 2.3 and later you can use a squiggly heredoc (<<~) to suppress the leading whitespace of content lines: def test <<~END First content line. Two spaces here. No space here. END end test # => “First content line.\n Two spaces … Read more
It looks like you are entering The Lost World here. I don’t think the problem is with c-bindings in racc either. Ruby memory management is both elegant and cumbersome. It stores objects (named RVALUEs) in so-called heaps of size of approx 16KB. On a low level, RVALUE is a c-struct, containing a union of different … Read more
You were close, have to add just a few more characters: (?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\”.\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t] )+|\Z|(?=[\[“()<>@,;:\\”.\[\]]))|”(?:[^\”\r\\]|\\.|(?:(?:\r\n)?[ \t]))*”(?:(?: \r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\”.\[\] \000-\031]+(?:(?:( ?:\r\n)?[ \t])+|\Z|(?=[\[“()<>@,;:\\”.\[\]]))|”(?:[^\”\r\\]|\\.|(?:(?:\r\n)?[ \t]))*”(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\”.\[\] \000-\0 31]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[“()<>@,;:\\”.\[\]]))|\[([^\[\]\r\\]|\\.)*\ ](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\”.\[\] \000-\031]+ (?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[“()<>@,;:\\”.\[\]]))|\[([^\[\]\r\\]|\\.)*\](?: (?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\”.\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z |(?=[\[“()<>@,;:\\”.\[\]]))|”(?:[^\”\r\\]|\\.|(?:(?:\r\n)?[ \t]))*”(?:(?:\r\n) ?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\”.\[\] \000-\031]+(?:(?:(?:\ r\n)?[ \t])+|\Z|(?=[\[“()<>@,;:\\”.\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\”.\[\] \000-\031]+(?:(?:(?:\r\n) ?[ \t])+|\Z|(?=[\[“()<>@,;:\\”.\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t] )*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\”.\[\] … Read more
You actually want TestClass.instance_methods, unless you’re interested in what TestClass itself can do. class TestClass def method1 end def method2 end def method3 end end TestClass.methods.grep(/method1/) # => [] TestClass.instance_methods.grep(/method1/) # => [“method1”] TestClass.methods.grep(/new/) # => [“new”] Or you can call methods (not instance_methods) on the object: test_object = TestClass.new test_object.methods.grep(/method1/) # => [“method1”]