If you want to rotate a GameObject, your best bet is to use a Transform's localEulerAngles. Don't go modifying the rotation directly. That is a quaternion, not a rotation in degrees. Even if you know what quaternions do, manipulating them directly is unintuitive at the very best.
So knowing that, you don't need to do a while lot more to your code. Just make sure it's a proper MonoBehaviour and do something like the following:
using UnityEngine;
using System.Collections;
public class Rotator : MonoBehaviour
{
private float currentRotation = 20.0f;
void OnGUI()
{
currentRotation = GUI.HorizontalSlider(new Rect(35, 75, 200, 30), currentRotation , 0.0f, 50.0f);
transform.localEulerAngles = new Vector3(0.0f, currentRotation, 0.0f);
}
}
This, in line with your pseudo-code, rotates the object which as that script between 0 and 50 degrees around its Y axis, based on the slider input.