29

When I tried to post an answer with the following content:

ha = a.group_by(&:itself).map{|k, v| [k, v.length]}.to_h
hb = b.group_by(&:itself).map{|k, v| [k, v.length]}.to_h
ha.merge(hb){|_, va, vb| (va - vb).abs}.inject([]){|a, (k, v)| a << [k] * v}.flatten

the post was automatically changed to:

group_by(&:itself).map{|k, v| [k, v.length]}.to_h hb = b.group_by(&:itself).map{|k, v| [k, v.length]}.to_h ha.merge(hb){|_, va, vb| (va - vb).abs}.inject([]){|a, (k, v)| a << [k] * v}.flatten

That is, the code formatting with four spaces before each line was removed, and the initial ha = a. was also trimmed.

6
  • Did you add a line before the code?
    – Braiam
    Commented Dec 18, 2015 at 1:59
  • @Braiam No. If I added a line before with a few periods, then the problem disappeared.
    – sawa
    Commented Dec 18, 2015 at 2:00
  • 2
    Was it a code-only post?
    – PM 77-1
    Commented Dec 18, 2015 at 16:43
  • @PM77-1 Yes, it was.
    – sawa
    Commented Dec 18, 2015 at 16:44
  • 1
    Thank goodness the first variable wasn't called gimmehtehcodezpls ;) Commented Dec 19, 2015 at 18:55
  • Any progress on the bug/feature fix?
    – sawa
    Commented Jun 19, 2016 at 10:46

3 Answers 3

17

This is caused by the automatic greetings removal, even though the regular expression shouldn't actually hit this case.

It removed any "ha" at the beginning of a post, and continues to remove stuff on the line until it hits "punctuation", in this case the period before group_by.

Changing the variable name to anything that doesn't fit the greetings regexp does fix the issue.

The greetings removal probably shouldn't be run on parts formatted as code.

1
  • That seems to be the case.
    – sawa
    Commented Dec 19, 2015 at 13:40
5

group_by(&:itself).map{|k, v| [k, v.length]}.to_h hb = b.group_by(&:itself).map{|k, v| [k, v.length]}.to_h ha.merge(hb){|_, va, vb| (va - vb).abs}.inject([]){|a, (k, v)| a << [k] * v}.flatten

^ Result of copy & pasting the code and formatting with Ctrl-K. Preview looked correct

2
  • 1
    Nope, it doesn't...
    – Braiam
    Commented Dec 18, 2015 at 1:58
  • 2
    @Braiam You're right. However, the preview window looked fine to me.
    – Rob Mod
    Commented Dec 18, 2015 at 1:58
5

Let's see...

ha = a.group_by(&:itself).map{|k, v| [k, v.length]}.to_h
hb = b.group_by(&:itself).map{|k, v| [k, v.length]}.to_h
ha.merge(hb){|_, va, vb| (va - vb).abs}.inject([]){|a, (k, v)| a << [k] * v}.flatten

if it works.


I'm presuming it trims all the spaces in the first line of the post, which I believe is actually good (if the preview warned you about it).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .