Skip to content

Instantly share code, notes, and snippets.

@Vaguery
Created March 1, 2010 19:54
Show Gist options
  • Save Vaguery/318739 to your computer and use it in GitHub Desktop.
Save Vaguery/318739 to your computer and use it in GitHub Desktop.
def replace_point(which,new_junk)
raise ArgumentError,"Cannot replace #{which}th program point" if which < 1
raise ArgumentError,"Cannot replace #{which}th program point" if which > self.points
raise ArgumentError,"Cannot insert #{new_junk.class}" unless new_junk.kind_of?(ProgramPoint)
result = self.deep_copy
if which == 1
result.linked_code = new_junk
else
to_replace = result[which]
parent = result.linked_code.detect do |wrapper|
wrapper.contents.include?(to_replace) if wrapper.respond_to?(:contents)
end
parent_index = parent.contents.find_index(to_replace)
parent.contents[parent_index] = new_junk
end
return result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment