title: Converting Ruby to C#
body: <p>Need to convert the following code from Ruby to C#. However I'm kind of puzzled by the use of the yield keyword and the general syntax of Ruby. Can anyone that knows a little bit Ruby please help out and convert the code </p>
  
  <pre><code>class &lt; &lt; Cache
  STALE_REFRESH = 1
  STALE_CREATED = 2
  
  # Caches data received from a block
  #
  # The difference between this method and usual Cache.get
  # is following: this method caches data and allows user
  # to re-generate data when it is expired w/o running
  # data generation code more than once so dog-pile effect
  # won't bring our servers down
  #
  def smart_get(key, ttl = nil, generation_time = 30.seconds)
    # Fallback to default caching approach if no ttl given
    return get(key) { yield } unless ttl
  
    # Create window for data refresh
    real_ttl = ttl + generation_time * 2
    stale_key = "#{key}.stale"
  
    # Try to get data from memcache
    value = get(key)
    stale = get(stale_key)
  
    # If stale key has expired, it is time to re-generate our data
    unless stale
      put(stale_key, STALE_REFRESH, generation_time) # lock
      value = nil # force data re-generation
    end
  
    # If no data retrieved or data re-generation forced, re-generate data and reset stale key
    unless value
      value = yield
      put(key, value, real_ttl)
      put(stale_key, STALE_CREATED, ttl) # unlock
    end
  
    return value
  end
  </code></pre>
  
  <p>end</p>