Question: Can anyone explain how to read this code and what it will do?

```
'D' * (num % 1000 / 500)

```

It is from a method for converting integers to Roman numerals. I don't understand how it functions.

Answer: 
It is pretty obfuscated indeed. I guess the idea was to put *one or zero* `D`s depending on if you get a number greater than 500 after you get the remainder of division by 1000.

The order of the operations:

```
num % 1000

```

`num` modulo 1000. Will leave the last three digits.

```
/ 500

```

Will see if the last three digits are greater than 500.

[String#\*](http://ruby-doc.org/core-2.2.3/String.html#method-i-2A) repeats a string:

```
'x' * 5 # => "xxxxx"

```

---

The reason that is needed is because `D` is the letter for 500. You will have only *one or zero* of these as `M` is the letter for 1000.
See [this](http://www.tutorialspoint.com/ruby/ruby_operators.htm) page and scroll down to Ruby Operators Precedence.

Multiplication, division, and modular arithmetic are all together, so precedence is left to right IIRC.

First, `num % 1000` is evaluated. Then, that is divided by `500`. That's then multiplied by 'D'.