<?xml version="1.0" encoding="UTF-8"?>
<codes type="array">
  <code>
    <code>&lt;?php
function get_handle($type)
{
	if (type=="r")
	{
		if (isset($this-&gt;fhr)) return $this-&gt;fhr;
		else user_error("File not open for reading");
	}
	elseif (type=="w")
	{
		if (isset($this-&gt;fhw)) return $this-&gt;fhw;
		else user_error("File not open for writing");
	}
	elseif (type=="a")
	{
		if (isset($this-&gt;fha)) return $this-&gt;fha;
		else user_error("File not open for appending");
	}
	elseif (!isset($type))
	{
		if (isset($this-&gt;fhr)) return $this-&gt;fhr;
		elseif (isset($this-&gt;fhw)) return $this-&gt;fhw;
		elseif (isset($this-&gt;fha)) return $this-&gt;fha;
		else user_error ("File not open");
	}
	else user_error("Invalid type");
}
?&gt;</code>
    <comment>This method feels like it's way more complicated than it should be.

Update: added &lt;?php to colourise.</comment>
    <created-at type="datetime">2010-02-09T00:35:08+00:00</created-at>
    <id type="integer">1171</id>
    <language>PHP</language>
    <permalink>return-the-appropriate-file-handle</permalink>
    <refactors-count type="integer">2</refactors-count>
    <title>Return the appropriate file handle</title>
    <trackback-url></trackback-url>
    <updated-at type="datetime">2010-02-09T10:17:05+00:00</updated-at>
    <user-id type="integer">1073</user-id>
    <user>
      <id type="integer">1073</id>
      <identity-url>http://macinnes.myopenid.com</identity-url>
      <name>Nathan</name>
      <rating type="float">0.0</rating>
      <refactors-count type="integer">4</refactors-count>
      <website nil="true"></website>
    </user>
  </code>
  <code>
    <code>stuff.each do |name|
  name = name.downcase
  #size
  if name =~ /(double|twin)/
    size = 2
  elsif name =~ /(single)/
    size = 1
  else name =~ /[0-9]/
    size = name.match(/[0-9]{1,2}/)[0]
  end
  
  #type
  if name =~ /(male)/
    type = "Male Dorm"
  elsif name =~ /(female)/
    type = "Female Dorm"
  elsif name =~ /(double)/
    type = "Double Bed"
  elsif name =~ /(twin)/
    type = "Twin Bed"
  elsif name =~ /(single)/
    type = "Single Bed"
  else
    type = "Mixed Dorm"
  end
  
  if name =~ /(private)/
    priv = '1'
  else
    priv = '0'
  end

  if name =~ /(ensuite)/
    ensuite = '1'
  else
    ensuite = '0'
  end
  
  name = name.gsub(/(dorm|male|female|double|single|beds|bed|private|ensuite|twin|[\d\(\)*])/,'').squeeze(' ')
  
  puts "Name: #{name}, Size: #{size}, #{type}, #{priv}, #{ensuite}"
end</code>
    <comment>any ideas on making this more concise?</comment>
    <created-at type="datetime">2009-09-10T13:15:41+00:00</created-at>
    <id type="integer">1030</id>
    <language>Ruby</language>
    <permalink>ungliness-and-long-too</permalink>
    <refactors-count type="integer">6</refactors-count>
    <title>ungliness and long too</title>
    <trackback-url></trackback-url>
    <updated-at type="datetime">2009-09-11T09:16:17+00:00</updated-at>
    <user-id type="integer">1697</user-id>
    <user>
      <id type="integer">1697</id>
      <identity-url>http://uberholden.myopenid.com</identity-url>
      <name>uberholden.myopenid.com</name>
      <rating type="float">0.0</rating>
      <refactors-count type="integer">0</refactors-count>
      <website nil="true"></website>
    </user>
  </code>
  <code>
    <code>  def show
    
    if params[:course_id] &amp;&amp; permitted_to?(:browse, :videos)
      @course = Course.find(params[:course_id])
      @video = @course.videos.find(:first) 
      add_crumb("Watching #{@video.title}", course_video_path(@course, @video))
      
    elsif params[:course_id]
      @course = Course.find(params[:course_id])
      @video = @course.videos.find(params[:id])
      add_crumb("Watching #{@video.title}", course_video_path(@course, @video))
   
    elsif !permitted_to?(:browse, :videos)
      @video = Video.find(params[:id])
      add_crumb("Watching #{@video.title}", video_path(@video))
      
    end</code>
    <comment>I thought of creating a before_filter to load the @course instance variable in to the show action - but it failed on the final elsif so I decided to manually add it in both conditions.</comment>
    <created-at type="datetime">2009-03-25T17:43:29+00:00</created-at>
    <id type="integer">802</id>
    <language>Ruby</language>
    <permalink>need-to-dry-this-if-else-up</permalink>
    <refactors-count type="integer">3</refactors-count>
    <title>Need to DRY this if-else up</title>
    <trackback-url></trackback-url>
    <updated-at type="datetime">2009-03-27T04:37:55+00:00</updated-at>
    <user-id type="integer">1343</user-id>
    <user>
      <id type="integer">1343</id>
      <identity-url>http://fnjord.myopenid.com</identity-url>
      <name>fnjord.myopenid.com</name>
      <rating type="float">0.0</rating>
      <refactors-count type="integer">1</refactors-count>
      <website></website>
    </user>
  </code>
</codes>
